WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Filtering custom taxonomies (5 posts)

  1. mvandemar
    Member
    Posted 1 year ago #

    I am attempting to extend functionality to my client's custom theme, and I am having issues trying to get query_posts() to pull a list of custom taxonomies filtered by category. The creation of the custom post type in functions.php is here:

    http://pastebin.com/MkrWvkx6

    Currently the site has a page that pulls in all of the posts, then filters out what is visible via jquery. The query that pulls in the posts is this:

    query_posts( array( 'post_type' => 'myportfoliotype', 'paged' => $paged, 'posts_per_page' => 80))

    This works, but as I said pulls in everything. What they want now is 2 custom templates that pulls in only 2 specific categories each. I can't do the filtering via jquery since it doesn't work visually to do that in this case. I am attempting to pull in just the 2 categories, but for some reason no variation of the following code seems to work:

    query_posts( array( 'post_type' => 'myportfoliotype', 'paged' => $paged, 'posts_per_page' => 80, 'tag_id' => '9' ))

    Everything I have tried either still pulls in all posts, or pulls in none of them. Any suggestions are appreciated, thanks.

    -Michael

    ps. Does anyone know of a function to dump the raw query that query_posts generates? If I could see what the actual query was doing with each variation I tried and compared that to the info in wp_postmeta it might help in figuring out where the issue lies.

  2. mvandemar
    Member
    Posted 1 year ago #

    Also, the tag_id filter in the query_posts() I posted above is only the most recent variation I tried. I also tried filtering by cat, category, category_name, etc.

    -Michael

  3. mvandemar
    Member
    Posted 1 year ago #

    I am still stumped on this one, any thoughts or insights?

    -Michael

  4. mvandemar
    Member
    Posted 1 year ago #

    In case anyone else stumbles upon this and is in need of an answer, I did get one here:

    http://wordpress.stackexchange.com/questions/87095/filtering-custom-taxonomies

    The solution involves using the tax_query inside of the query_postscall:

    query_posts( array( 'post_type' => 'myportfoliotype', 'paged' => $paged, 'posts_per_page' => 80,
    		'tax_query' => array(
    			array(
    				'taxonomy' => 'categories', //or tag or custom taxonomy
    				'field' => 'id',
    				'terms' => array('9', '13')
    			)
    		)
    	 ));

    The parameter is listed in the WP_Query documentation, but not in the query_posts page.

  5. manuki
    Member
    Posted 8 months ago #

    thank you for posting answer!!

Topic Closed

This topic has been closed to new replies.

About this Topic