skip to Main Content

I am using Advanced Custom fields and i have made 2 custom field types one matches where a get all the matches and i use some custom fields here and one called predictions which i want to display them in front page using the followin query

<?php
        $headlines = 0;
        $headlines_lead =  get_field('sixed_relationship','alpha_brief', false);
        $args = array(
                'posts_per_page'    => 4,
                'offset'            => 0,
                'post_type'         => array('analysis_stoiximatos', 'printed_post'),
                'post__in'          => $headlines_lead,
                'post_status'       => 'publish',
                'orderby'           => 'post__in'
               
                );
        ?>

        <?php $banner_query2 = new WP_Query( $args ); ?>
        
    
<?php 
   
    
?>


<div class="central_main_area">

<h1>matches </h1>

<?php
    $entos_edras_omada = get_field('entos_edras_omada');

    

?>
<?php if( $banner_query2->have_posts() ): ?>
    <ul>
        <?php while ( $banner_query2->have_posts() ) : $banner_query2->the_post(); ?>
            <li>
                <a href="<?php the_permalink(); ?>">
                    

                    <?php the_title();
                            setup_postdata( $args );

                    global $post;
                    
                    var_dump(the_field( 'entos_edras_omada', get_the_id() ));

                    ?>
                    

                    
                </a>
            </li>
        <?php endwhile; ?>
    </ul>
<?php endif; ?>
<section class="oloi_oi_agones" id="oloi_oi_agones">


</section>

the problen is that i get the title of each match BUT the field returns null….

2

Answers


  1. Chosen as BEST ANSWER

    Because it is relationship custom fields it needs another loop inside

    $post_id = get_the_ID();
                        //echo $post_id;
                        // $entos_edras_omada = get_field('entos_edras_omada',$post_id); 
                        //$dish_meta = get_post_meta( $post_id, '_entos_edras_omada', true );
                        //echo $dish_meta;
                        //echo $entos_edras_omada;
                        ?>
                        <?php
                            $featured_posts = get_field('locations');
                            if( $featured_posts ): ?>
                                <?php foreach( $featured_posts as $post ): 
    
                                    // Setup this post for WP functions (variable must be named $post).
                                    setup_postdata($post); ?>
                                    
                                        <span><?php the_field( 'entos_edras_omada' ); ?></span>
                                        
                                <?php endforeach; ?>
                                <?php 
                                // Reset the global post object so that the rest of the page works correctly.
                                wp_reset_postdata(); ?>
                            <?php endif; ?>
    

  2. You shouldn’t need to setup_postdata when you’re within the loop. I’m not sure that I understand $headlines_lead = get_field('sixed_relationship','alpha_brief', false); This looks incorrect to me. What kind of field is this? I’m guessing a relationship field and you’re trying to get an array output of post IDs, correct?

    Try this:

    <?php
    $headlines = 0;
    
    $headlines_lead =  get_field('sixed_relationship', false, false);
    
    $args = array(
        'posts_per_page'    => 4,
        'offset'            => 0,
        'post_type'         => array('analysis_stoiximatos', 'printed_post'),
        'post__in'          => $headlines_lead,
        'post_status'       => 'publish',
        'orderby'           => 'post__in'
    );
    
    $banner_query2 = new WP_Query( $args );
    ?>
    
    <div class="central_main_area">
        <h1>matches </h1>
    
        <?php
        if( $banner_query2->have_posts() ):
            ?>
            <ul>
                <?php
                while ( $banner_query2->have_posts() ) : $banner_query2->the_post();
                    ?>
                    <li>
                        <a href="<?php the_permalink(); ?>">
                            <?php
                            the_title();
                            var_dump(the_field( 'entos_edras_omada', get_the_id() ));
                            ?>
                        </a>
                    </li>
                <?php endwhile; ?>
            </ul>
            <?php
        endif;
        wp_reset_postdata();
        ?>
    </div>
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search