Get posts category from only one parent
-
I’m not sure how to return only the children categories that belong to cat 406. My code returns 10 posts from cat 406, but some of those posts are in a child cat of 406 but sometimes are in another category as well.
Can I somehow check if ‘$post_cat[0]->slug’ belongs to cat 406?
echo '<ul class="artist-thumbs">'; $thumbnails = get_posts('posts_per_page=10&cat=406'); foreach ($thumbnails as $thumbnail) { $post_cat = get_the_category( $thumbnail->ID ); echo '<li><a class="side-thumb" href="' . get_permalink( $thumbnail->ID ) . '" title="' . esc_attr( $thumbnail->post_title ) . '">'; if ( has_post_thumbnail($thumbnail->ID)) { echo get_the_post_thumbnail($thumbnail->ID, 'thumbnail'); $upload_dir = wp_upload_dir(); $art_image = ''.$upload_dir['basedir'].'/icons/'.$post_cat[0]->slug.'.png'; if (file_exists($art_image)) { echo '<p class="artist-latest"><img src="https://dailydoseoftattoos.com/wp-content/uploads/icons/'.$post_cat[0]->slug.'.png" alt="'.$post_cat[0]->slug.'"/>'.$post_cat[0]->name.'</p>'; }else{ echo '<p class="artist-latest">'.$post_cat[0]->name.'</p>'; } } else { } echo '</a></li>'; } echo '</ul>';
Viewing 5 replies - 1 through 5 (of 5 total)
Viewing 5 replies - 1 through 5 (of 5 total)
- The topic ‘Get posts category from only one parent’ is closed to new replies.