Dynamic Category Page That Shows Posts From the Current Category

HOW IS THIS SO DIFFICULT TO FIND!?

It’s like the most basic functionality of a WordPress category page, but all I keep finding is “never ever use query_posts!” and “use WP_Query” and a bunch of code to do extra crap I don’t need, or code that uses query_posts.

I literally just need to find the code for the WP_Query to retrieve the current category and spit out those posts.

That’s it.

Why has this become the unachievable quest?

Everyone stops short of just getting the right code out there.


Well now, this sounds like a clue: https://www.smashingmagazine.com/2014/08/customizing-wordpress-archives-categories-terms-taxonomies/

A great use of modifying the WP_QUERY object using pre_get_posts is to add posts from a custom post type to the category archive. By default, custom post types are not included in this query.

Maybe this is my problem.

YES! FINALLY!

CSS Tricks to the rescue: https://css-tricks.com/snippets/wordpress/make-archives-php-include-custom-post-types/

Added that chunk of code to my functions, and I removed the WP_query gobbly-gook from my archive template. Didn’t expect it to work but it’s finally working!!!!!

So that explains why I couldn’t find the code I was looking for: because it’s baked into WordPress–so long as I tell WordPress to include my custom post types in it’s baked-in-ness.

Posted in Blog • September 5, 2020 | No Comments »

Leave a Reply

Deborah J Designs