This is my structure:
+Parent1
-Child Cat 1
-Child Cat 2
+Parent2
-Child Cat 4
-Child Cat 5
--> 2 posts have been published in child category 1
--> 3 posts have been published in child category 2
--> 7 posts have been published in child category 4
--> 9 posts have been published in child category 5
No posts have been published directly in parent1 and parent2. Published in child category only.
I want the posts of the child category to be displayed in the corresponding parent category.
For example, in parent category 1, all 5 child category posts(2+3) should be displayed.
And in parent category 2, all 16 child posts(7+9) should be displayed.
Also, the priority of displaying posts in the parent category 1&2 should be with sticky posts.
This is my code:
global $post;
$category = get_the_category($post->ID);
$category = $category[0]->cat_ID;
$myposts = get_posts(
array(
'posts_per_page'=>20,
'offset' => 0,
'cat' => $category,
'post_status'=>'publish',
'order'=>'ASC',
'ignore_sticky_posts' => 0
),
);