[wp-trac] Re: [WordPress Trac] #6484: have_posts does not seem to work outside of the loop

WordPress Trac wp-trac at lists.automattic.com
Mon Mar 31 16:50:04 GMT 2008


#6484: have_posts does not seem to work outside of the loop
---------------------+------------------------------------------------------
 Reporter:  jsherk   |        Owner:  anonymous
     Type:  defect   |       Status:  new      
 Priority:  normal   |    Milestone:  2.5.1    
Component:  General  |      Version:  2.5      
 Severity:  normal   |   Resolution:           
 Keywords:           |  
---------------------+------------------------------------------------------
Old description:

> This is test code, but I use something similar to display recent posts
> from multiple blogs on my home page which is external to the wordpress
> directory.
>
> This code worked on WP 2.3 but when I upgraded to 2.5 it stopped working.
> If you stick this code in the main wordpress directory, have_posts
> returns nothing, even though there are posts. If you put in a known
> exisitng post id, then you will see that it properly displays the post
> title, but have_posts still says there is nothing!
>
> <?php
> require('wp-blog-header.php');
> $myid=10; //put a post id here that you know is valid
> $mytest = get_post($myid);
> echo "Known good post id ".$myid." returns: ".$mytest->post_title;
> $mytest = have_posts();
> if ($mytest=="") { $mytest="nothing"; }
> echo " and have_posts() returns: ".$mytest;
> ?>
>
> Is this a bug, or has something changed that requires changes to how this
> works?

New description:

 This is test code, but I use something similar to display recent posts
 from multiple blogs on my home page which is external to the wordpress
 directory.

 This code worked on WP 2.3 but when I upgraded to 2.5 it stopped working.
 If you stick this code in the main wordpress directory, have_posts returns
 nothing, even though there are posts. If you put in a known exisitng post
 id, then you will see that it properly displays the post title, but
 have_posts still says there is nothing!

 {{{
 <?php
 require('wp-blog-header.php');
 $myid=10; //put a post id here that you know is valid
 $mytest = get_post($myid);
 echo "Known good post id ".$myid." returns: ".$mytest->post_title;
 $mytest = have_posts();
 if ($mytest=="") { $mytest="nothing"; }
 echo " and have_posts() returns: ".$mytest;
 ?>
 }}}

 Is this a bug, or has something changed that requires changes to how this
 works?

-- 
Ticket URL: <http://trac.wordpress.org/ticket/6484#comment:2>
WordPress Trac <http://trac.wordpress.org/>
WordPress blogging software


More information about the wp-trac mailing list