Support

Account

Home Forums Feature Requests Post_object post

Solving

Post_object post

  • Dear ACF

    Please help me to show all post via Post_Object

    I did use this code :

    <?php 
    $post_id = get_the_ID();
    $args = array(
    	'post_type'	=> 'post',
    	'posts_per_page'=> -1,
    	'meta_query'	=> array(
    	array(
    		'key' => 'attraction_in',
    		'value' =>  $post_id,
    		'compare' => 'IN'
    		)
    	)
    );
    
    // query
    $wp_query = new WP_Query( $args );
    if ($wp_query->have_posts() ) :
    	echo '<div class="single-destination-list-items">';
    	echo '<h3>Top attractions in '.get_the_title( $post_id ).'</h3>';
    	echo '<ul>';
    while( $wp_query->have_posts() ) { $wp_query->the_post();
    ?>
    <li>
    <a href="<?php the_permalink(); ?>"><?php echo get_the_post_thumbnail( $page->ID, 'tours' ); ?></a>
    <div class="items-right">
    <a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a>
    </div>
    </li>
    <?php
    }
    echo '</ul>';
    echo '</div>';
    endif;
    ?>

    It not working fine, can not load more post the same Selected post

  • If the post object field can only have one value then what you have should work. It will not work if your post object field allows multiple selections. If that’s the case then you need to change the meta query to

    
    $args = array(
    	'post_type'	=> 'post',
    	'posts_per_page'=> -1,
    	'meta_query'	=> array(
    	array(
    		'key' => 'attraction_in',
    		'value' =>  '"'.$post_id.'"',
    		'compare' => 'LIKE'
    		)
    	)
    );
    

    this is explained in the “single-location.php” section of this page https://www.advancedcustomfields.com/resources/querying-relationship-fields/

  • Thanks to John Huebner

    But your code not working, do you have full code for this query

    Thanks

  • I can only adjust what you’ve posted using the information you’ve given me. If it’s not working then I suggest looking that the documentation I linked to above. Other than the query arguments, there’s not much more I can give you.

    the only other thing that I can suggest is to change the variable name for you query.
    $wp_query = new WP_Query( $args ); You should not use $wp_query because it will override the main query. Change it to anything else like $my_query or $related_query or just $query.

Viewing 4 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic.