2

I have a custom post type 'license' with custom post statuses 'active,inactive,cancel,expire'. However when I run a get_posts query to get only posts with active status it returns all the posts irrespective of the status.

$active_licenses = get_posts( array(
        'post_type' => 'license',
        'post_status'    => 'active',
        'posts_per_page' => -1,
        'orderby'        => 'ID',
        'order'          => 'DESC',

    ) );

I am unable to figure out what am I doing wrong.

  • What does your register_post_status() call look like? Add that to your question too. – Otto Apr 23 '14 at 21:21
  • I am using Piklist to create post types and settings pages. Here is the call $post_types['license'] = array( 'labels' => piklist('post_type_labels', 'License'), 'title' => __('Enter a new License'), 'public' => false, 'rewrite' => false, 'query_var' => false, 'status' => array( 'inactive' => array ( 'label' => 'Inactive'), 'active' => array ( 'label' => 'Active'), 'expired' => array ( 'label' => 'Expired'), 'cancel' => array ( 'label' => 'Cancelled') ) ); – Vijay Sharma Apr 23 '14 at 21:38
  • I don't know what piklist is, so you should probably ask the author of that code about it. – Otto Apr 23 '14 at 22:20
  • Try using new WP_Query instead of get_posts – Bainternet Apr 23 '14 at 22:33
  • Vijay - it's best to add code to your existing question so it's more readable. Can you add the full code for your reigster_post_status() - also make sure you've flushed your permalinks. – Steven Jones Apr 24 '14 at 10:51
0

I would try use 'perm' => 'readable' in your query arguments to make sure WP_Query runs a permissions check.

0

You need to register the custom post status.

Adding the following function (adapted to your custom status) to functions.php solved this problem for me:

/**
 * Register custom post status: license
 */
function register_custom_post_status_license() {
    $custom_status = 'license';
    $count_label = 'License <span class="count">(%s)</span>';

    register_post_status( $custom_status, array(
        'label'                     => _x( 'License', 'post' ),
        'public'                    => true,
        'exclude_from_search'       => false,
        'show_in_admin_all_list'    => true,
        'show_in_admin_status_list' => true,
        'label_count'               => _n_noop( $count_label, $count_label ),
    ) );
}
add_action( 'init', 'register_custom_post_status_license' );

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.