0

I have a function called singlePromotion which works base on ACF, I called function in home page but I can't add HTML with foreach loop, this is my code :

<?php
                // WP_Query arguments
                $args = array(
                    'post_type' => array('post'), 'posts_per_page' => -1
                );

                // The Query
                //$edition = new WP_Query($args);
                if(!$post || !$post->ID)
                        $post = get_post(HOME_ID);
                // The Loop
                if ($post && $post->ID) {


                        // get projects
                        $posts = get_field('home_promotions',HOME_ID);
                        foreach ($posts as $key => $promo) {
                            $items2 = singlePromotion($promo,0,5);
                            //exit(print_r($items,1));

                        foreach ($items2 as $value) {

                            ?>
                    <div class="col-sm-1-5 grid-item" onclick="">
                        <article class="entry-item">
                            <div class="front">
                                <div class="entry-thumb">
                                    <img src="<?php echo $image; ?>"  alt="">
                                </div>
                                <?php if( get_field('imdb_rate') ): ?>
                                <div class="rate"><?php the_field('imdb_rate') ?></div>
                            <?php endif; ?>
                            </div>
                            <div class="back">
                                    <h4 class="entry-title mbm"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h4>
                                    <div class="pg mbm">G</div>
                                    <div class="desc-mv"><div>
                                        <span>تاریخ انتشار:</span><?php the_field('movie_release'); ?>
                                    </div>
                                    <div>
                                        <span>ژانر:</span>
                                        <?php
                                        $categories = get_the_category();
                                $separator = ' | ';
                                $output = '';
                                if ( ! empty( $categories ) ) {
                                    foreach( $categories as $category ) {
                                        $output .= '<a href="' . esc_url( get_category_link( $category->term_id ) ) . '" alt="' . esc_attr( sprintf( __( 'View all posts in %s', 'textdomain' ), $category->name ) ) . '">' . esc_html( $category->name ) . '</a>' . $separator;
                                    }
                                    echo trim( $output, $separator );
                                }
                                ?>
                                    </div>
                                    <div>
                                        <span>مدت نمایش:</span>
                                        <?php the_field('movie_time') ?>
                                    </div>
                                    <div>
                                        <span>زبان:</span>
                                        <?php the_field('movie_lang'); ?>
                                    </div>
                                </div>
                                <div class="entry-button">
                                    <a data-fancybox data-type="iframe" data-src="https://player.vimeo.com/video/38156752"><i aria-hidden="true" class="fa fa-play"></i>تریلر</a>
                                    <a href="<?php the_permalink(); ?>"><i aria-hidden="true" class="fa fa-exclamation"></i>جزییات</a>
                                        </div>
                                    </div>
                        </article>
                    </div>

                            <?php
                }                    
            }




                }

                // Restore original Post Data
                wp_reset_postdata();
                ?>

If I uncomment this line exit(print_r($items,1)); I'll see array correctly. but inside foreach i don't see related posts.

please help

1
  • can you show the dump data of exit(print_r($items2,1)); Commented Nov 8, 2017 at 8:30

1 Answer 1

0

If the acf fields you are looking for are from the HOME_ID page/post then add the given line to setup post data with $post as below:

if ($post && $post->ID) {

setup_postdata($post); // Add this line in your code

                    // get projects
                    $posts = get_field('home_promotions',HOME_ID);
Sign up to request clarification or add additional context in comments.

3 Comments

please provide the dump data of $items2 and also specify which data can't be fetched and also mention the post/page which will have the required data to show.
ca you send me an email so i can contact you?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.