WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have trouble in getting post in a custom post type category. I have code below but it doesnt work well. It still get posts in another category.

    $query= null;
    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
        'post_type' => get_post_type(),
        'post_status' => 'publish',
        'paged' => $paged,
        'post_type_cat' => 'featured', // get_post_type() will return post_type, I add _cat -> post_type_cat
        //'orderby' => 'rand',
        'posts_per_page' => 1,
        'meta_query' => array(
                'key' => '_expiration_date',
                'value' => array(0, current_time('timestamp')),
                'compare' => 'BETWEEN'
    $query = new WP_Query($args);
<?php if ( $query->have_posts() ) : $query->the_post(); ?>
<?php get_template_part( 'template/featured' ); ?>
<?php else : ?>
<?php get_template_part( 'template/nofeatured' ); ?>
<?php endif; ?>
<?php wp_reset_query(); ?>

Can you help me?

Thank you

share|improve this question
What is the category name? – montrealist May 7 '13 at 4:59
up vote 1 down vote accepted

As far as I know there is no such parameter as post_type_cat, you want to use either cat or if querying posts in a custom taxonomy you would use a taxonomy query.

Category query example;

$query = new WP_Query( 'cat=2,6,17,38' );


$query = new WP_Query( 'category_name=staff' );

See the following Codex entry for even more ways to query by category;


Taxonomy query example;

$args = array(
    'post_type' => 'post',
    'tax_query' => array(
            'taxonomy' => 'people',
            'field' => 'slug', //can be set to ID
            'terms' => 'bob' //if field is ID you can reference by cat/term number
$query = new WP_Query( $args );

See this entry for more details:


share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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