[WP_query] Custom Taxonomy and Categories (3 posts)

  1. DFL
    Posted 3 years ago #

    Hi everybody, I try custom taxonomy items listed. But I need listed for cat ID.

    This is working good.

    $query_faqitems = new WP_Query(array('post_type' => 'dfl_faq','posts_per_page' => -1));

    but if I add a cat this not working. I looking here doc

    $query = new WP_Query( 'cat=4' );

    I using this line
    $query_faqitems = new WP_Query(array('post_type' => 'dfl_faq','posts_per_page' => -1, 'cat' => 24));

    Can you help me for this? Sorry for my English.

  2. Andrew Bartel
    Posted 3 years ago #

    So because cat is a custom taxonomy, you need to use a tax query. The category parameter for wp_query only works for stock WordPress posts.

  3. DFL
    Posted 3 years ago #

    Andrew thanks for great hint and help -- tax query :) I now understand :D This working

    $args = array(
     'post_type' => 'dfl_faq',
     'posts_per_page' => -1,
     'tax_query' => array(
    	 'taxonomy' => 'faqcategory',
    	 'field' => 'id',
    	 'terms' => array('22','24')
    $query_faqitems = new WP_Query( $args );

Topic Closed

This topic has been closed to new replies.

About this Topic


No tags yet.