Get_posts not returning any posts when used with switch_to_blog

Question

I’m attempting to pull in some order information from the “shop_orderpost_type.

This is on a multisite network, so I’m using switch_to_blog(1). When I set the post type as “post” it works great and I get the posts from the correct site. When I set the post_type to “shop_order” I get nothing, despite there being 20,000 ‘shop_order‘ records in the database.

switch_to_blog(1);
$args = array (
        //'post_type' => 'post',
        'post_type' => 'shop_order',
        'posts_per_page' => 2,
        );
$posts = get_posts( $args );
restore_current_blog();
var_dump($posts);

--------------------------------------------------

>>> Share a link to this question, just copy and paste the code bellow on your web page <<<

<a href="https://www.wptricks.com/question/get_posts-not-returning-any-posts-when-used-with-switch_to_blog/">

Get_posts not returning any posts when used with switch_to_blog</a>
0
, , Alek Hartzog 5 months 0 Answers 83 views 0

Leave an answer