• I try to get the woocommerce memberships but get_post looks not working right

    there are 19 post from post type wc_user_membership
    withe the folloing post statuses > 1 null 2 public 16 wcm-active

    I use the follow arguments

    $args = array(
    	'numberposts'   => -1,
    	'post_type'     => 'wc_user_membership',
    	'post_status'   => 'auto-draft',
    );
    $posts = get_posts( $args );

    return all 19 post

    $args = array(
    	'numberposts'   => -1,
    	'post_type'     => 'wc_user_membership',
    	'post_status'   => 'publish',
    );
    $posts = get_posts( $args );

    return 2 posts

    $args = array(
    	'numberposts'   => -1,
    	'post_type'     => 'wc_user_membership',
    	'post_status'   => 'wcm-active',
    );
    $posts = get_posts( $args );

    return all 19 post`

    I make test also with post and pages, arguments works only when ‘post_status’ => ‘publish’

    I working on WP multisite and I use before the code switch_to_blog( 2 ) and after restore_current_blog(), but even is I don’t use it and visit the blog #2 I receive the same result.

    Thanks

    (edit)
    I try also WP_Query() with same results, seems like cannot recognize non default post statues

    • This topic was modified 3 years, 5 months ago by Thodoris.
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘get_posts not behaves correct when I use post_status argument’ is closed to new replies.