the_category_ID for children
-
I have the following code in my parent category template:
<?php $cat = get_query_var('cat'); $args = array( 'child_of' => $cat, 'orderby' => 'name', 'order' => 'ASC' ); $attachment_id = get_field('cat_image', 'category_'. the_category_ID( $echo ) .''); $size = "header-img"; // (thumbnail, medium, large, full or custom size) $categories = get_categories($args); foreach($categories as $category) { echo '<p><a href="' . get_category_link( $category->term_id ) . '" title="' . sprintf( __( "View all posts in %s" ), $category->name ) . '" ' . '>' . wp_get_attachment_image( $attachment_id, $size ).'</a> </p> '; echo '<p> Name: '. $category->name . '</p>'; echo '<p> Description:'. $category->description . '</p>'; echo '<p> Post Count: '. $category->count . '</p>'; } ?>What this does is get’s the category name, link, post count and description for each child of that parent as well as an image in the custom field of the child category page.
The problem I’m having is getting the child category’s ID in this code
$attachment_id = get_field('cat_image', 'category_'. the_category_ID( $echo ) .'');All that seems to be happening is that is grabbing the current category ID and not that of the child.
Pulling my hair out at the moment and would really appreciate any ideas, thoughts or help.
The topic ‘the_category_ID for children’ is closed to new replies.