Last active
November 10, 2015 20:04
-
-
Save marcosfreitas/5db7cdacb398571968c9 to your computer and use it in GitHub Desktop.
WORDPRESS: Retrieve children of a parent category - get_categories()
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* Subcategories of "Journals" (id: 6) */ | |
$categories = get_categories('child_of=6&hide_empty=0'); | |
foreach ($categories as $cat): | |
/* This get the total of posts in current category of the loop.*/ | |
$total_of_posts_in_category = (int) $cat->count; | |
$current_category_name = $cat->name; | |
/* For each category, make the loop for the amount of posts */ | |
/* New wordpress query object - passing the arguments */ | |
$journals_query = new WP_Query('category_name='.$current_category_name.'&show_posts=-1&order_by=name&order=asc'); | |
/* This is the loop for the current category retrieved */ | |
while($journals_query->have_posts()): | |
$journals_query->the_post(); | |
// [custom code...] | |
endwhile; | |
endforeach; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment