Help with WordPress posts query

I have a multisite installation and I have one subsite that contains shared posts that I want all sites to have access to. The shared posts have their own post ID range, like post ID > 1000000000… I want to be able to modify the WordPress query on posts so that these shared posts are added to any subsite post query.

So for instance site A has posts 1, 2, 3 … and site B has posts 10, 11, 12 and the shared site has posts 1000000001, 1000000002, etc. but if you do a search of posts for site A you get 1, 2, 3, 1000000001, 1000000002, etc. even though the posts are on different sites.

I want shared site post will be included in any subsites post query. How can I achieve this?

  • Ash
    • WordPress Hacker

    Hello Michael

    I am not aware of any such way to customize the query to get posts from other subsites. How’s about adding another query and add in the loop?

    Here is a stackoverflow thread that may give you an idea:

    You can use post___in attribute to get posts which ID is greater than the number, like:

    $post_ids = range(10000000, 100000000);

    $args = array('numberposts' => 10,
    'tag' => 'my-tag',
    'post__in' => $post_ids');

    Hope it helps! Please feel free to ask more questions if you have any.

    Have a nice day!



  • Michael
    • Flash Drive

    I can do this for a post or a page, but the objective is to do it automatically for the entire site such that other plugins and queries which search posts table “see” a union of the current subsite posts and shared posts. I have accomplished this in my own plugin by writing functions to replace the standard WordPress functions like get_permalink() with a function that switches to the shared blog as needed, but this is messy and there are limitations. In particular, I am using ACF and there is a post object query field with a dropdown and a corresponding query for that dropdown contents that I would like to intercept to include posts from the shared site.

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.