What i’m trying to do is simple: Make a loop through all subsites and catch post info from a specific post type and putting it all on a array.
Here’s the simplified version of the code:
<?php $blog_list = get_blog_list( 0, 'all' ); foreach ($blog_list as $blog) : switch_to_blog($blog); $end_query = new WP_Query(array('post_type' => 'enderecos', 'post_per_page' => '-1')); if ($end_query->have_posts()) : while ($end_query->have_posts()) : $end_query->the_post(); echo $post->ID . " - " . get_the_title($post->ID) . "<br />; endwhile; endif; endforeach; ?>
Oh, another important thing: This code is running on 3.4.2 version of wp.
We can’t update it because the themes used were custom made by the last developer and updating it would cause a lot of stuff to break, and we are already recreating the theme as a new, but i still need to fix some things on the old code while then.
The code up there works perfectly, but there’s a small bug:
If a POST ID already exists on the MAIN BLOG, then the loop catches the info from the post on the main blog instead of the one in the subsite.
For instance, let’s say a subsite has two posts on that post type, one is ID 37 and the other, 38.
And then, on the main blog, there’s a PAGE POST with 38 but not one with 37.
When the loop reaches the post 37, the correct title appears. When it reaches 38… It gets the title from the page post id 38 from the MAIN blog.
I have no idea of the reason behind this behavior, did anyone here had this problem before?
Thanks in advance.
- The topic ‘Problems with custom query on multisite’ is closed to new replies.