Home Forums General Issues Related posts by post object


Related posts by post object

  • I’m having issues using a post object field to pull in posts from one post type into the posts from another post type. I’ve actually done this before and it’s worked fine – in fact this is almost identical code to the other site – but for whatever reason on this site it doesn’t work.

    Code is below. Couple of notes:

    – If you set the meta_value manually to a post ID (eg: ’68’) it outputs the correct posts, but using $post->ID outputs everything from that post type.

    – It also doesn’t seem to be outputting any of the custom fields – only general wordpress fields. eg: get_permalink($post->ID) seem to work but get_field(‘short_title’) doesn’t.

    $posts = get_posts(array(
    	'numberposts' => -1,
    	'post_type' => 'offer',
    	'meta_key' => 'bookmaker',
    	'meta_value' => $post->ID
    	echo '<h2>Offers</h2>';
    	foreach($posts as $post)
    		echo '<div class="reviewoffer"><div class="reviewoffertitle"><a href="' . get_permalink($post->ID) . '">' . get_field('short_title') . '</a></div><div class="reviewoffersummary">' . get_field('summary') . '</div></div>';
    	echo '';
    <?php wp_reset_postdata(); ?>
Viewing 1 post (of 1 total)

The topic ‘Related posts by post object’ is closed to new replies.