Support » Networking WordPress » How to query over the network

  • Resolved MathiasAeschlimann


    I have a WP 3.8.1 Multisite installation with 3 blogs, they’re all in one db, prefixed wp_, wp_2_ and wp_3_.

    In a template in wp_ I try to to display all posts from wp_, wp_2_ and wp_3_ which have a category xxx attached. I want to display the posts chronologically. I tried this query:

    SELECT *
    FROM $wpdb->posts
        	INNER JOIN $wpdb->term_relationships ON $wpdb->posts.ID= $wpdb->term_relationships.object_id
        	INNER JOIN $wpdb->term_taxonomy ON $wpdb->term_relationships.term_taxonomy_id = $wpdb->term_taxonomy.term_taxonomy_id
        	INNER JOIN $wpdb->terms ON $wpdb->term_taxonomy.term_id=$wpdb->terms.term_id WHERE $wpdb-> = 'xxx'
        ORDER BY $wpdb->posts.post_date DESC

    This works only for the current blog, ie it doesn’t include wp_2_ and wp_3_.

    How do I retrieve all posts with category xxx from wp_, wp_2_, wp_3_ (instead of only wp_)?

Viewing 4 replies - 1 through 4 (of 4 total)
  • Moderator Ipstenu (Mika Epstein)


    Lead Plugin Wrangler

    Well. You’d have to use switch_to_blog() to call each one in turn. But may I ask what the goal is? If you just want to show all posts from a category from ALL sites, you may want to use this:

    That will psudeo import all posts to a ‘tags’ blog, which will let you organize by category, and still link back to their REAL home (per site), and thus make SEO happy 🙂

    Yes, this is what I want. But instead of one place I have three places with three distinct categories.

    Moderator Ipstenu (Mika Epstein)


    Lead Plugin Wrangler

    I think you misunderstood me. Do you want to pull three places with three categories into one place?

    I understood you. I needed the functionality of the plugin for three distinct conglomerations. I was able to do it myself by looping trough the blogs with switch_to_blog(). Thank you!

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘How to query over the network’ is closed to new replies.