Archived topic
Any advanced docs? Elements - Content Template - Apply to Post w term - Location
22 replies · Started by Brad on February 4, 2022
Hi Tom,
Sincere thanks for the reply. Coming from the "showcase" page, clicking the "category" or "tag" button brings you to the corresponding site/category/name-of category page.
(Links to Dropbox screenshots below)
David (GP Team) lined me up with a reference link / function to include CPT to show up in default Wp Core categories.
Code:
// show CPT in Categories
// https://wpbeaches.com/show-custom-post-types-category-archive-page/
function j66co_show_cpt_archives( $query ) {
if( is_category() || is_tag() && empty( $query->query_vars['suppress_filters'] ) ) {
$query->set( 'post_type', array(
'post', 'nav_menu_item', 'showcase'
));
return $query;
}
}
add_filter( 'pre_get_posts', 'j66co_show_cpt_archives' );
The Problem:
Once the function is added, CPT's do show up in the category archives but the category archives loose all GenerateBlock Content Block Element layout. Everything rolls back to use Wp default.
The goal:
Have...
https://blocks-01.j66labs.co/category/web-app/
https://blocks-01.j66labs.co/category/video-production/
https://blocks-01.j66labs.co/category/campaign/
https://blocks-01.j66labs.co/category/j66co-product/
https://blocks-01.j66labs.co/category/web-design/
https://blocks-01.j66labs.co/category/photography/
(Tag Example)
https://blocks-01.j66labs.co/tag/points-co/
"Accept"
the GenerateBlock "content template and header" element grid layout from...
https://blocks-01.j66labs.co/photography/
The GenerateBlocks Display location is set / or has been set to all category archives, all showcase archives. I've tried the force function display workaround but can't figure out the ID if the Wp archive category pages. Var dump (I'm probably not doing it correctly) is returning 0 when I add it to the archive-showcase.php file.
There's probably a more efficient way to do this via GB elements via hook. I'm not sure how.
Dropbox screenshots
https://www.dropbox.com/s/q9sogwghf5m2tuc/GP-cat01.jpg?dl=0
https://www.dropbox.com/s/967st83w8zt1z4n/GP-cat02.jpg?dl=0
To confirm, does this particular issue go away if you remove that pre_get_posts filter?
Are you still using this function as well?: https://generatepress.com/forums/topic/change-post-per-page-custom-post-type-archive-page-element-templates-skipped/#post-2103500
It should prevent the pre_get_posts filter from interfering with the way Elements are displayed.
No the issue is still there. For testing I’m using a Snippets Plugin. Snippets in question are turned off. Problem still there.
1.
Show CPT in Categories function is TURNED ON. GenerateBlocks Elements layouts disappear
2.
Post per page to 3 function is TURNED OFF. GenerateBlocks Elements layouts disappear
Pre_get_post filter is commented out / not active
______
Update:
If i turn both off, GenerateBlocks / GeneratePress works. Layout is as it should be but that defeats the purpose as of course CPT categories don’t show up in categories and for some reason photography pagination still doesn’t work.
Objective with reducing post per archive page is that I’m image heavy. No need to load +20 mb on images in 10 post total on mobile even using tinypng. It I load 4 - 6 posts that should make UX “useable”.
Hi Brad,
Let's try modifying everything into one snippet so it's easy to follow:
Can you remove both the the filters with pre_get_posts and try to merge it?
The code should be something like this:
add_filter( 'generate_elements_custom_args', function( $args ) {
$args['suppress_filters'] = true;
return $args;
} );
function j66co_photography_posts_per_page($query) {
if ( is_post_type_archive( 'photography' ) ) {
$query->set('posts_per_page', 3);
}
if( ( is_category() || is_tag() ) && empty( $query->query_vars['suppress_filters'] ) ) {
$query->set( 'post_type', array( 'post', 'showcase') );
return $query;
}
}
add_action('pre_get_posts', 'j66co_photography_posts_per_page', 99, 1);
I've modified the condition:
if( is_category() || is_tag() && empty( $query->query_vars['suppress_filters'] ) )
to
if( ( is_category() || is_tag() ) && empty( $query->query_vars['suppress_filters'] ) )
Ok. Just added the condensed snippet. Unfortunately same problem.
https://blocks-01.j66labs.co/photography/
Then … page 2… opps not found.
Ok. Just added the condensed snippet. Unfortunately same problem.
https://blocks-01.j66labs.co/photography/
Then … page 2… opps not found.
Please see my suggestion here. (Debugging)
Resolved via other support thread noted above.
Thanks for letting us know. :D