I create a new post status called "old" with the code below.
$args = [
'label' => _x( 'Old', 'page' ),
'label_count' => _n_noop( 'Old (%s)', 'Old (%s)' ),
'public' => false,
'internal' => true,
'show_in_admin_all_list' => true,
'show_in_admin_status_list' => true,
'exclude_from_search' => true,
'publicly_queryable' => true,
];
register_post_status( 'old', $args );
When I try to get all post in any status, I couldn't get the posts which is marked as "Old".
$args = array(
'meta_key' => 'parent_post_id',
'meta_value' => 123,
'post_status' => 'any',
'post_type' => 'any',
);
$posts = get_posts( $args ); // posts without "old"
If I pass the "Old" as a post_status value with "any" in array, it works.
$args = array(
'meta_key' => 'parent_post_id',
'meta_value' => 123,
'post_status' => ['any', 'old'],
'post_type' => 'any',
);
$posts = get_posts( $args ); // posts with "old"
What should I do to get posts which are marked as "old" with "any" option in Wp Query?
If you read the docs
'any' - retrieves any status except those from post statuses with 'exclude_from_search' set to true (ie trash and auto-draft).
Look at your code:
'exclude_from_search' => true,
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.