• $args = array('post_type' => 'message', $taxonomy => $term, 'posts_per_page' => 25, 'paged' => $paged );
    $wp_query = new WP_Query($args);

    The code above gets ALL post_types (not just messages) for the taxonomy term $term.

    But if we change it to:

    $args = array('post_type' => 'message', 'posts_per_page' => 25, 'paged' => $paged );
    $wp_query = new WP_Query($args);

    it gets the correct post_types of ‘message’. I can’t seem to get any query to work correctly that combines post_type with a taxonomy selection – but they work fine individually.

    I have read everything I can and am sure the top section of code is correct – does anyone see anything wrong with it?

Viewing 8 replies - 1 through 8 (of 8 total)
  • Thread Starter d910qf

    (@d910qf)

    Sent email to wp-hackers list:

    The post_type is ignored for taxonomy based queries. See trunk,
    query.php, line 2034.

    -Otto

    I’m looking for the same result. Is there someone who find a solution?

    That problem was fixed in the 3.0 beta.

    having same exact problem running latest trunk.

    <?php
    $wpq = array (post_type =>'movies','taxonomy'=>'series','term'=>$term->slug);
    $query = new WP_Query ($wpq);
    while ( have_posts()) : the_post(); ?>
    
    <?php the_title(); ?>
    do other stuff
    
    <?php endwhile; ?>

    returns all post_types not just movies.

    Is my code syntax wrong or something as you state it works in beta?

    I was having similar problems (3.0b2), but found this worked:-

    $wpq = array (post_type =>'movies','series'=>$term->slug);

    For this to work, though, when the taxonomy is setup the ‘query_var’ parameter should either not be set or (in this case) set to ‘series’.

    @markauk
    Here is what I have figured out.

    1. If I only have a taxonomy applied to a single post_type, then the above function works perfectly.

    2. If I have a taxonomy ‘series’ applied to multiple post_types then it does not do the multi filter. It returns the output of both post_types.

    Meaning, I have the ‘series’ taxonomy applied to both ‘movies, albums’. When I run the above function it always outputs the values for both movies and values with the taxonomy ‘series’.

    definitely a bug.

    thanks

    @anointed
    It works for me with taxonomies attached to multiple post types.

    Here’s the code I am using (it’s extracted from various places in the site I am working on, but I think that’s all the essential bits):-

    (1) register the new post type

    register_post_type( 'history',
    	array(
    			'label'	=>	'History',
    			'public' => true,
    			'show_ui' => true,
    			'publicly_queryable' => false,
    			'exclude_from_search' => true,
    			'hierarchical' => false,
    	)
    	);

    (2) register the taxonomy

    register_taxonomy('featured', array('page','post','history'), array(
    		'hierarchical' 	=> TRUE,
    		'label' 			=> 'Featured Pages',
    		'singular_label'	=> 'Featured Page',
    		'public' 			=> TRUE,
    		'show_ui' 			=> TRUE,
    		'show_tagcloud' 	=> FALSE,
    		'rewrite' 			=> FALSE
    	));

    (3) do the query

    $args = array(
    		'post_type'	 =>	array('page','post','history'),
    		'post_status' =>	'publish',
    		'featured'	=> 'test',
    	);
    
    $wp_query = new WP_Query($args);

    @markauk
    It turns out that I identified not a ‘bug’ per say, but functionality that currently does not exist in wp.
    https://core.trac.www.ads-software.com/ticket/13582

    Basically we can’t currently filter via post type + taxonomy dynamically yet.

    Michael said:

    A url such as post_type = ‘sermons’ + custom taxonomy = ‘series’ plus term = term->slug is not supported

    This is all pushing the boundaries of my abilities, but I am now trying to figure out how to add the functionality to the core. I’ve never before written direct db queries logic before. Heck, not even sure what the proper terminology is.

    I’m sure that many people are going to want to do this, so I am trying as hard as I can to get it figured out for not just me but for everyone.

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘WP_Query and custom taxonomies’ is closed to new replies.