WordPress.org

Ready to get started?Download WordPress

Forums

[WP_query] Custom Taxonomy and Categories (3 posts)

  1. DFL
    Member
    Posted 1 year 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
    Member
    Posted 1 year 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
    Member
    Posted 1 year 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(
    	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

Tags

No tags yet.