Display posts of child category in template

I have searched, and searched, and tried, and finally found……..

<?php
global $wpdb;
$categories = $wpdb->get_results("SELECT $wpdb->terms.term_id AS id, name, description from $wpdb->terms INNER JOIN $wpdb->term_taxonomy ON $wpdb->terms.term_id = $wpdb->term_taxonomy.term_id WHERE parent="$cat" ORDER BY name ASC");
foreach($categories as $category) :
?>

<h2><?php echo $category->name; ?></h2>
    <ul>
    <li><a href="https://wordpress.stackexchange.com/questions/147767/<?php echo get_category_link($category->id);?>"><b><?php echo $category->description; ?></b></a>
Posts on this campaign:
<?php global $post;
$myposts = get_posts("category=$category->id");
foreach($myposts as $post) : setup_postdata($post);
?>
- <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
<?php endforeach; ?>
    </li>
    </ul> 

<?php endforeach; ?>

Leave a Comment

tech