WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] How do you Properly Query Posts in a Multisite Network? (18 posts)

  1. travelvice
    Member
    Posted 3 years ago #

    Howdy, a brief multisite question for the brain trust:

    In a multisite environment, what's the procedure for querying the posts of a site within a network (as opposed to a traditional config)?

    ***

    I've got a travelogue in a subdomain that I'm interested in folding into an MS install on the root.

    Off the root I'm going to be creating specific country & city Pages, with lists of travelogue entries (relevant to each Page's city or country).

    Simply put, the Page domain.com/peru/lima/ would contain (amongst many other things) a list of all (not just recent) travelogue.domain.com entries from -- yep, you guessed it -- Lima, Peru.

    'Peru' is a category and 'Lima' is the value of a custom field for that post.

    I will ultimately need to query, at the root level, posts in the travelogue that are within a certain category and contain a specific custom field. :p

  2. travelvice
    Member
    Posted 3 years ago #

    Perhaps simply using WPMU's switch_to_blog would be appropriate, however very intensive when used across several hundred Pages.

    <?php switch_to_blog(2); ?>
    // do stuff
    <?php restore_current_blog(); ?>

    My guess is this would probably OK so long as W3 Total Cache stores this Page output to alleviate some of the burden.

  3. Gather all your posts into one blog with this plugin:

    http://wordpress.org/extend/plugins/wordpress-mu-sitewide-tags/

  4. travelvice
    Member
    Posted 3 years ago #

    Hi! Always lovely to have your thoughts.

    Alas, I was hoping to avoid leaning on that specific plugin to do this, but I can see that as of WP3.1 there's still a lot of drama surrounding switch_to_blog and W3 Total Cache (#14992).

    Seems like it's one or the other at this point.

    Correct me if I'm wrong, but it would appear that unless I'm using Sitewide Tags, there's now little difference between folding the travelogue into a Multisite network or leaving it be on a single install. (as it pertains to pulling posts in a category with a custom field, that is)

  5. except wp super cache works just fine with SWT as they are from the same developer.

    SWT does what you want.

    that link about querying posts is for within one install - not for getting posts from a separate install into another one.

  6. travelvice
    Member
    Posted 3 years ago #

    Right. It's my understanding that WP Super Cache isn't having the same conflicting problems with switch_to_blog that W3 Total Cache is. Or maybe it's just going unreported. I don't know.

    I certainly have no doubt that SWT is the answer for most folks, but I'm not supporting a large network, simply the root and one sub-site.

    However, as I'm on shared hosting, the bottom line on all this will be what ultimately consumes fewer server resources:
    1) using caching with SWT;
    2) using caching with switch_to_blog; or
    3) using caching with a custom select query

  7. 1) using caching with SWT;

    this one.

    You only have TWO blogs.

  8. Yeah, #2 wouldn't work well anyway. Use Caching and SWT. Works fine :)

  9. travelvice
    Member
    Posted 3 years ago #

    Thanks for your thoughts you two. Will have to look into if option #3 is just as speedy (cached), as my desire to not maintain/bloat with another plugin is high on my list. SWT seems to be the answer repeated again and again (for good reason), but I'm not one to shy away from the less traveled road.

  10. I think querying multiple tables and merging the info will be more CPU intensive than just doing that with SWT personally (there's a reason that's currently the way we do it ;) ) but I'm not the best with SQL queries.

  11. travelvice
    Member
    Posted 3 years ago #

    FYI:
    This is just a follow-up for searchers who come across this topic.

    With the awesome help of Curtiss, there's another option on the table for people to consider.

    I used this for Pages on site #1 where I wanted to pull and list Posts out of site #2.

    global $wpdb;
    $wpdb->set_blog_id(2);
    $wpdb->set_prefix($wpdb->base_prefix);
    
    --- YOUR CODE ---
    
    $wpdb->set_blog_id(1);
    $wpdb->set_prefix( $wpdb->base_prefix );

    Detailed examples can be found here.

    Enjoy!

  12. Ron Rennick
    MultiSite Guru
    Posted 3 years ago #

    I strongly recommend that you do not use the code snippet as an alternative to switch_to_blog().

  13. OffCourse2010
    Member
    Posted 3 years ago #

    I am developing a network wordpress site and I would like to have all posts shown (and searcheable) in the main page.

    From what I have read in many forums, it allways comes back to SWT. However one can see that wordpress.com itself has this feature and they should be using an enhanced version of the wordpress script, I trust.

    How do they do it? No site would be bigger so they must have it fully dialed. It can't be just hardcore servers running the core functions of wordpress, can it?

    Thanks

  14. They are using something similar to SWT.

  15. OffCourse2010
    Member
    Posted 3 years ago #

    Someone suggested preparing a batch that would copy and update all posts from the subsites to the main site overnight.

    Is this similar to the SWT approach?

  16. Yes. that's exactly what it does. Why reinvent the wheel?

    The guy who made the3 SWT plugin works for wp.com.

    The stuff on the front page of wp.com is actually hand selected, not pulled in automatically from all blogs. They have *millions*.

  17. OffCourse2010
    Member
    Posted 3 years ago #

    Thanks Andrea

    I imagined that there would be something like a hand selection for the posts to feature in the homepage, but what about searching. It searches across all the blogs.

    Is it the same feature (duplicate posts) and the search is within the main blog only or do you think it is a search engine that goes out and actually searches all the content in the domain?

  18. or do you think it is a search engine that goes out and actually searches all the content in the domain?

    I definitely do not think it is this.

    I'm not 100% on what they do for the searches, but that way above totally does not scale.
    You really do have to plunk a copy of every post somewhere and work from that.

Topic Closed

This topic has been closed to new replies.

About this Topic