Support » Plugins » Hacks » Post from child category

  • Resolved gordon34


    Hi there everyone!
    I’ve a little problem with query that’s showing post from child category.

    I have one category called ie MainCat. This category had two child categories. One of those child cat have one child-child category. The structure is below.

    – Child1
    – Child-Child1
    – Child2

    I create some ajax slidedown menu that showing child categories of MainCat and their posts. But unfortunatly this solution showing all post from all categories in MainCat when i want to view only post from (first) Child cat. Only post from Child1, Child2 etc. exclude post from Child-Child1. Below is code that i’m using now. Please give some hint about this case how to exclude posts from Child-Child categories.

    $catQuery = $wpdb->get_results("
    		SELECT * FROM $wpdb->terms AS wterms
    		INNER JOIN $wpdb->term_taxonomy AS wtaxonomy ON ( wterms.term_id = wtaxonomy.term_id )
    		WHERE wtaxonomy.taxonomy = 'category'
    		AND wtaxonomy.parent = 3
    		AND wtaxonomy.count > 0");
    	foreach ($catQuery as $category) { ?>
    <li><a href="#"><?php echo $category->name; ?></a>
    		<?php if(query_posts('cat='.$category->term_id) > 1) : ?>
    				while (have_posts()) : the_post(); ?>
    <li><a>"><?php echo the_title(); ?></a></li>
Viewing 1 replies (of 1 total)
  • gordon34


    ok. i solved the problem by myself.

    here’s the cheat:

    in this line
    <?php if(query_posts('cat='.$category->term_id) > 1) : ?>

    i change “cat” thing into
    <?php if(query_posts(array("category__in" => array($category->term_id))) > 1) : ?>

    that’s all if somebody need it in the future.

Viewing 1 replies (of 1 total)
  • The topic ‘Post from child category’ is closed to new replies.