I am trying to create a WP_Query on my category.php where it shows posts from a custom post type called "doctors" and it will query the posts based on the current slug in the url. So if it is at "website.com/categories/psychiatrists" it will show all of the custom post type "doctors" that have the category "psychiatrists"
I hope that makes sense. What I have right now however is a query that filters by the category title instead of the slug, which is causing a lot of issues if the title doesn't match the slug. When one of the SEO people go in and change the title of the category it breaks all of the links.
Any help would be super appreciated! I'm still a little new with this wordpress and php.
Here is the query I have right now:
<?php $args = array( 'post_type' => 'doctors', 'category_name' => single_cat_title('',false), 'posts_per_page' => -1 ); $loop = new WP_Query( $args ); ?> <?php if ( $loop->have_posts() ) : while ( $loop->have_posts() ) : $loop->the_post(); get_template_part( 'content', 'providers' ); endwhile; else : ?> <p><?php _e( 'Sorry, no posts matched your criteria.' ); ?></p> <?php endif; ?>