I wanted to ask if there is a shorter way then by checking each time if the post is coming from a specific category.
As you can see the categories cover the alphabet, A B C etc and each time I check with a custom loop etc, is there a shorter way to write this or am I on track.
At the moment how I have it set up works.
<?php if ( is_category( 'a' ) ) { ?>
<?php $THEresults = array( 'post_type' => 'plants', 'orderby'=> 'title', 'order' => 'ASC', 'category_name' => 'a',);
$loop = new WP_Query( $THEresults );
?>
<?php while ( $loop->have_posts() ) : $loop->the_post();?>
<?php get_template_part( 'content' ); ?>
<?php endwhile; ?>
<?php wp_reset_postdata(); ?>
<?php } elseif ( is_category( 'b' ) ) { ?>
<?php
$THEresults = array( 'post_type' => 'plants', 'orderby'=> 'title', 'order' => 'ASC', 'category_name' => 'b',);
$loop = new WP_Query( $THEresults );
?>
<?php while ( $loop->have_posts() ) : $loop->the_post();?>
<?php get_template_part( 'content' ); ?>
<?php endwhile; ?>
<?php wp_reset_postdata(); ?>
EDIT FROM COMMENTS
I have a custom post type ‘plants’ and the posts created are arranged into categories in alphabetical form such as category A, B, C etc. When you click on category A then the above code will only display those posts in category A, for B, C etc. The above works but didn’t know if there was a shorter way to check if the post belongs to category A, B, C etc
in_category()
?is_category()
dosen't check if a post belongs to category; that functions check if you are in a category archive page (for exmpale yoursite.com/category/health). Can you explain what you are trying to do?