You are complicating everything with a custom query. You should never ever replace the main query with a custom one on the home page or any type of archive page, this breaks page functionalities as you have seen. You should take your time and read this post I have done on this particular issue
You just need the default loop in category.php, nothing else
if ( have_posts() ) {
while ( have_posts() ) {
the_post();
//Your html and template tags
}
}
EDIT
Just some extra info for interest sake
You don’t need all that statements to check the category. You can simply access the queried object and get whatever needed info from there. get_queried_object()
returns the complete queried object, get_queried_object_id()
returns the current object id. So you could have just passed the following to your query arguments
'cat' => get_queried_object_id(),
instead of doing al those plenty if/else
statements
EDIT 2
It seems your biggest headche is actually your custom post type. By default, they are excluded from the main query on category pages. With the changes you’ve made according to recommendation from my original past, you will not see custom post type posts, just posts from the default post type post
As I have described in the linked post, you should use pre_get_posts
to alter the main query to suite your needs. And this what you should do here as well.
In your functions.php, you need to add the following code, this will add your custom post type to your category pages
add_action( 'pre_get_posts', function ( $q )
{
if ( !is_admin() && $q->is_main_query() && $q->is_category() ) {
$q->set( 'post_type', array( 'post', 'plants' ) ); //This will show normal posts and plants
}
});
The above will now show normal posts and posts from the post type plants. If you don’t need to show normal posts, just remove post
from the array