How to get custom statuses to show up in the archive?
-
Hi there,
I’m trying to get a custom post type with custom post statuses to show up in the custom post type archive. However only posts with the status “published” show up.This is part of the purchase order tracking system that I’m building. The post type is called purchase_order. I’ve already modified the archive query to only show posts that were created by the logged in user but when I try to modify it to include all post statuses I still only get published posts. This is true even when I try replacing ‘any’ with ‘draft’ for example. The code is below.
How can I include custom statuses in a post type archive? Thanks!
add_action( 'pre_get_posts', 'load_purchase_orders' ); function load_purchase_orders( $query ) { $user = wp_get_current_user(); if ( ! is_admin() && $query->is_main_query() && ! $query->is_post_type_archive('purchase_order')) { //match posts to the logged in user. this works perfectly: $query->set( 'author', $user->ID ); //display all posts regardless of post status. this doesn't work: $query->set( 'post_status', 'any' ); } }
Viewing 5 replies - 1 through 5 (of 5 total)
Viewing 5 replies - 1 through 5 (of 5 total)
- The topic ‘How to get custom statuses to show up in the archive?’ is closed to new replies.