WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] How to query over the network (5 posts)

  1. MathiasAeschlimann
    Member
    Posted 5 months ago #

    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->terms.name = '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_)?

  2. 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: http://wordpress.org/plugins/wordpress-mu-sitewide-tags/

    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 :)

  3. MathiasAeschlimann
    Member
    Posted 5 months ago #

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

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

  5. MathiasAeschlimann
    Member
    Posted 5 months ago #

    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!

Reply

You must log in to post.

About this Topic