setup_postdata is not returning any values

In order for the template tags to work the global $post variable needs to be set properly, your $post is probably local to the loop or file.

Put somewhere before the loop global $post

But realy, just don’t do it, all the functions you use there can accept a post object or post id as parameter and there is no need to use globals. something like

foreach( $post_objects1 as $p): 
 ?>
 <h1><a href="https://wordpress.stackexchange.com/questions/214731/<?php echo get_permalink($p->ID); ?>">Title is <?php echo get_the_title($p->ID); ?></a></h1>
 <?
endforeach;

Leave a Comment