Support » Fixing WordPress » [WP_query] Custom Taxonomy and Categories

  • DFL

    (@dfl)


    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.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Andrew Bartel

    (@andrew-bartel)

    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.

    DFL

    (@dfl)

    Andrew thanks for great hint and help — tax query 🙂 I now understand 😀 This working

    $args = array(
     'post_type' => 'dfl_faq',
     'posts_per_page' => -1,
     'tax_query' => array(
    	array(
    	 'taxonomy' => 'faqcategory',
    	 'field' => 'id',
    	 'terms' => array('22','24')
    	)
    	)
    );
    $query_faqitems = new WP_Query( $args );
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘[WP_query] Custom Taxonomy and Categories’ is closed to new replies.