Support » Fixing WordPress » Display only children posts within a custom taxonomy

  • Hi

    I am creating a site with a custom taxonomy, and custom post types. The could be several levels to the taxonomy, with the lowest level containing the custom post types (the products).

    Level 1 > Level 2a > products
    Level 1 > Level 2b > products

    The problem I am having is that I can’t hide the products when I am viewing Level 1. For some reason it is displaying the products from Level 2a and 2b as well.

    This is the code I am using:

    <?php $recent = new WP_Query(“post_type=product&customtaxonomy=$slug&posts_per_page=$posts_per_page”); ?>
    <?php while($recent->have_posts()) : $recent->the_post();?>

    Many thanks for any tips 🙂

Viewing 3 replies - 1 through 3 (of 3 total)
  • anyone?

    I am using this within a taxonomy-taxname.php:

    $term = $wp_query->get_queried_object();
    	$termID = $term->term_id;
    	$taxonomyName = "directories";
    	$termchildren = get_term_children( $termID, $taxonomyName );
    	$args = array(
    		'posts_per_page' => -1,
    		'tax_query' => array(
    			'relation' => 'AND',
    				'taxonomy' => 'directories',
    				'field' => 'id',
    				'terms' =>$term->term_id,
    				'taxonomy' => 'directories',
    				'field' => 'id',
    				'terms' => $termchildren,
    				'operator' => 'NOT IN',
    	query_posts( $args );

    The reference for this code is on

    This gets the children of the current directory (E.g. Level 1)
    Then excludes them from the query.
    That way when you are in Level 1 it will only show Level 1 posts, when you are in sub directory Level2a it will show only those ones.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Display only children posts within a custom taxonomy’ is closed to new replies.