-
owlsliveintrees
Hello,
I’m trying to create an archive template for a CPT made with ACF using the Query block.
It works for the NEW taxonomies I created with ACF, but it doesn’t work with the built-in category taxonomy.
So website.com/format/in-person/ works fine, but website.com/category/hummus doesn’t bring up any of the posts.
Do the built-in category taxonomy just not work with CPTs?
-
Hi there,
Did you assign the category taxonomy to the CPT?
And as far as I know, category archive only displays post post type, no CPT.
If you want to show CPT on category archive, add this PHP code. change
cpt-a
to the actual cpt slug.function include_cpt_in_category_archive( $query ) { // Check if we're on a category archive page and it's the main query, not in admin if ( ! is_admin() && $query->is_main_query() && $query->is_category() ) { // Include both 'post' and your custom post type $query->set( 'post_type', array( 'post', 'cpt-a' ) ); } } add_action( 'pre_get_posts', 'include_cpt_in_category_archive' );
Adding PHP: https://docs.generatepress.com/article/adding-php/
-
owlsliveintrees
Hi Ying – creating a custom post type with ACF allows you to utilize the existing category taxonomy.
It’s been working great until I tried to utilize a loop template to create an archive page element.
-
Alvind
Hi there,
In your Loop Template element, select the Query block and enable the “Inherit query from template” option.
After that, add the snippet Ying provided above so that the custom post type entries are included in the category archive query.
-
owlsliveintrees
WELL THAT WORKED.
Thank you Ying. Alvin – you too.
-
No Problem 🙂
- You must be logged in to reply to this topic.