WordPress.org

Support

Support » Plugins and Hacks » Edit Flow » [Resolved] How to get custom statuses to show up in the archive?

[Resolved] 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' );
    	}
    }

    http://wordpress.org/extend/plugins/edit-flow/

Viewing 5 replies - 1 through 5 (of 5 total)
  • Nevermind. typos in my code. it works now! *headslap

    Here’s the working code for those who are curious:

    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'))
        {
            //show all purchase orders that are open
            $query->set( 'post_status', array('new-order','assigned-pm','assigned-xfer','in-progress','ready-for-editing','complete') );
            //only show those purchase orders that are created by the logged in user
            $query->set( 'author', $user->ID );
        }
    }
    Plugin Author Daniel Bachhuber

    @danielbachhuber

    Thanks for sharing, yguez

    Hi ever body pleae in witch file i hav to add this code thanks for help .

    Hi Maher,
    Just put it in your functions.php file.
    Yaron

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘[Resolved] How to get custom statuses to show up in the archive?’ is closed to new replies.
Skip to toolbar