I’ve created a fairly basic form that allows users to filter post type archives by their taxonomies.
On custom post types this is super simple to do by simply setting ?taxonomy_name=term_slug
in the URL. WP also supports an array of terms with ?taxonomy_name[]=term_slug1&taxonomy_name[]=term_slug2
.
What’s odd however is that on the archive for non custom post types (ie the “post” post type) this stops working. Setting ?category=term_slug
does absolutely nothing.
How can I, preferably without using pre_get_posts
or anything else more advanced, filter the regular posts by their taxonomies (category
and post_tag
)?
Even if default posts are stored in same table but they have different behavior and different characteristics.
CPT has post type archive but default post type archived is called as blog and the taxonomy filter is called as tag/category archive.
You can access the category/tag archive using
For categories:
/?cat={category_id} //e.g. ?/cat=5
For tags:
/?tag={tag_slug} //e.g. ?/tag=my_tag_slug
If you are willing to use pre_get_posts
you can customize this in the way you want (That is what I love in WordPress <3) else stick with default way.
Another note: I recommend to leave the default posts for blog never use them for building something custom with those types instead use CPT as many as you want to expend your site from blog to CMS 🙂