Archived topic
Missing Posts for Custom Post Type Category Archive
3 replies · Started by Tyler on November 20, 2021
Hi All!
We just finished migrating from a multisite setup for a few subdomains into 1 WP Instance using Custom Post Types.
One of our last issues is that our Post Type Categories aren't displaying a grid.
We have an element set up and it is registering for the cat. We have 2 columns set via a hook in our child theme.
We just have no posts in the category: https://getinspiredeveryday.com/canada/.
We want to avoid any custom templates and have been attempting to do everything within the means of GeneratePress like a boss! :)
Ha! Just figured it out!
I needed to hook into pre_get_posts to include them in the query!
function add_cpt_to_category_archive( $query ) {
if ( ! is_admin() && $query->is_main_query() ) {
if ( is_archive() || is_category() || is_home() ) {
// Add CPT to the category
$query->set( 'post_type', array( 'food', 'adventure' ) );
}
if ( $query->is_search() ) {
// Add CPT to the search
$query->set( 'post_type', array( 'food', 'adventure' ) );
}
}
}
add_action('pre_get_posts', 'add_cpt_to_category_archive' );
So my last question is what's the best practice to add the category title?
Hi there,
https://docs.generatepress.com/article/layout-element-overview/ks, .paging-navigation {
display: none;
}`
The h1.page-title selector is the problem.
As a note you can disable the H1 - content title using a Layout Element:
https://docs.generatepress.com/article/layout-element-overview/
You can set the dynamic display rule locations to where you want it disabled.