WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have created a custom query in hopes of showing the top posts from some child categories. The query has a big flaw: some posts belong to two categories; but, even if they get marked in BOTH categories, they only appear in one.

For example, a post marked in both "Navigating Difference" and "Learning Exchanges" will only appear in "Navigating Difference".

I also wonder if there's an easier way to do this: can I just query for all child categories of a certain category?

The query is:

<?php
    $posts = get_posts( 'numberposts=3&offset=0&showposts=3&cat=21,22,23,26,31,32,349');
    foreach ($posts as $post) :
        start_wp();
?>
<?php
    static $count1 = 0;
    if ($count1 == "3") {
        break;
    } else {
?>
share|improve this question

Use this instead as your loop query..

<?php
    query_posts( 'category_name=YOUR_CAT_NAME&showposts=15' );
    if ( have_posts() ) :
        while ( have_posts() ) :
        the_post(); 
?>
share|improve this answer

Generally, you can use get_term_children() to get the child category id from a specific parent category.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.