[wp-trac] [WordPress Trac] #6555: With multiple WP installs, calling functions from external directory always retrieves results from first blog

WordPress Trac wp-trac at lists.automattic.com
Wed Apr 2 20:05:38 GMT 2008


#6555: With multiple WP installs, calling functions from external directory always
retrieves results from first blog
---------------------+------------------------------------------------------
 Reporter:  jsherk   |       Owner:  anonymous
     Type:  defect   |      Status:  new      
 Priority:  normal   |   Milestone:  2.5.1    
Component:  General  |     Version:  2.5      
 Severity:  major    |    Keywords:           
---------------------+------------------------------------------------------
 This is hard to explain, but maybe the example will make sense:
 With multiple WP installs, calling functions from external directory
 always retrieves results from first blog, even when specifically
 referencing other blog directories.

 I have two seperate blog installs at mydomain.com/blog1 and
 mydomain.com/blog2. Note that mydomain.com is outside all the WP installs.

 An external program that tries to pull the posts out of each blog, always
 gets the blog1 posts, even when it should be getting blog2 posts. Here's
 how to recreate:

 Take the following code:

 {{{
 <?php
 //Displays the title of the 3 most recent posts in the blog
 require('./wp-blog-header.php');
 query_posts('showposts=3');
 if (have_posts()) : while (have_posts()) : the_post();
 the_title();
 ?><br />
 <?php endwhile; endif; ?>
 }}}

 Save it as BlogOnePosts.php and upload it to mydomain.com/blog1 directory.
 Now save the same code again as BlogTwoPosts.php and upload it to
 mydomain.com/blog2 directory.

 Go to mydomain.com/blog1/BlogOnePosts.php and you should see this:

 {{{
 blog1 post
 another post
 first post
 }}}


 Now goto mydomain.com/blog2/BlogTwoPosts.php and you will see this:

 {{{
 blog2 mypost
 second blog post
 first but not reallt post
 }}}

 As you can see each blog correctly displays it's own posts...


 Now take this code:

 {{{
 Blog 1<br />
 <?php include('/home/public_html/blog1/BlogOnePosts.php'); ?>
 <br /><br />
 Blog 2<br />
 <?php include('/home/public_html/blog2/BlogTwoPosts.php'); ?>
 }}}
 Save it as BlogPosts.php and upload it to your mydomain.com directory
 (outside both wordpress installs).


 Now goto mydomain.com/BlogPosts.php

 You will probably get an error message like this:

 {{{
 WARNING: require(./wp-blog-header.php) [function.require]: failed to open
 stream: No such file or directory in
 /home/public_html/blog2/BlogTwoPosts.php on line 3
 WARNING: require(./wp-blog-header.php) [function.require]: failed to open
 stream: No such file or directory in
 /home/public_html/blog2/BlogTwoPosts.php on line 3
 FATAL ERROR: require() [function.require]: Failed opening required './wp-
 blog-header.php' (include_path='.:/usr/lib/php:/usr/local/lib/php') in
 /home/public_html/blog2/BlogTwoPosts.php on line 3
 }}}

 To fix this error message...
 In the BlogOnePosts.php change this line:

 {{{
 require('./wp-blog-header.php');
 }}}

 to this line:

 {{{
 require('/home/public_html/blog1/wp-blog-header.php');
 }}}


 Now in the BlogTwoPosts.php change this line:

 {{{
 require('./wp-blog-header.php');
 }}}

 to this line:

 {{{
 require('/home/public_html/blog2/wp-blog-header.php');
 }}}


 Now got back to mydomain.com/BlogPosts.php, and you see that Blog 1 shows
 the three most recent posts correctly, but Blog 2 shows the three most
 recent posts from Blog 1 as well instead of it's own posts, like this:

 {{{
 Blog 1
 blog1 post
 another post
 first post

 Blog 2
 blog1 post
 another post
 first post
 }}}


 As you can see the call in BlogPosts.php for Blog 2 is specifically
 referencing blog2/BlogTwoPosts.php and the require statement within
 BlogTwoPosts.php is specifically referencing blog2/wp-blog-header.php but
 it is returning results from Blog 1 !!!

-- 
Ticket URL: <http://trac.wordpress.org/ticket/6555>
WordPress Trac <http://trac.wordpress.org/>
WordPress blogging software


More information about the wp-trac mailing list