Getting child category id (help with improving my code)
I have here hardcoded category id so I can pull in needed categories and their posts by category. But ideally I would like to get this by calling parent category to list child and post. My code works but that's not how I would like to do it and would like to hear any suggestions to improve. I'm still trying to figure this out myself as well.
Parent category is 'winners-2018'.
?php
$catz = array(6012,6013,6014,6015,6016);
foreach($catz as $i=$categ){
$cat_archive = get_category ($categ);
//var_dump($cat_archive);
global $wp_query;
$args = array_merge( $wp_query-query_vars,array(
'paged'=$paged,
'posts_per_page'=10,
'post_type' = 'winners',
'category_name' = $cat_archive-slug,
));
?
div class="outer"
div class="inner"
div class="inside"
h1?php echo $cat_archive-name; ?/h1
/div
div class="left-content winners_fullwidth ?php if(is_category()) { echo $cat_archive-slug;} ?"
div class="wrap-content clearfix"
?php
$cposts = get_posts(array(
'category'=$categ,
'orderby' = 'title',
'order' = 'ASC',
'posts_per_page'=10,
'post_type' = 'winners',
));
foreach ( $cposts as $post ) : setup_postdata( $post ); ?
div class="press-box"
?php if ( has_post_thumbnail() ) { ?
div class="art-image"
a href="?php echo get_permalink(); ?" title="?php the_title();?"?php the_post_thumbnail( 'square-blog' ); ?/a
/div
?php } ?
div class="art-right"
h2a class="perma" href="?php echo get_permalink(); ?"?php the_title();?/a/h2
?php the_excerpt();?
/div
/div
?php endforeach;?
?php wp_reset_query(); ?
/div!-- wrap-content --
/div!-- left-content --
/div
?php } ?
Topic get-children categories Wordpress
Category Web