Home › Forums › Support › Any advanced docs? Elements – Content Template – Apply to Post w term – Location
- This topic has 22 replies, 4 voices, and was last updated 4 years, 1 month ago by
Elvin.
-
AuthorPosts
-
February 12, 2022 at 11:54 pm #2116350
Brad
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=0https://www.dropbox.com/s/967st83w8zt1z4n/GP-cat02.jpg?dl=0
February 13, 2022 at 5:21 pm #2117196Tom
Lead DeveloperLead DeveloperTo confirm, does this particular issue go away if you remove that
pre_get_postsfilter?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_postsfilter from interfering with the way Elements are displayed.February 13, 2022 at 5:45 pm #2117210Brad
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 disappear2.
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”.
February 13, 2022 at 8:49 pm #2117287Elvin
StaffCustomer SupportHi 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'] ) )February 13, 2022 at 9:44 pm #2117323Brad
Ok. Just added the condensed snippet. Unfortunately same problem.
https://blocks-01.j66labs.co/photography/
Then … page 2… opps not found.
February 13, 2022 at 10:09 pm #2117346Elvin
StaffCustomer SupportOk. 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)
February 23, 2022 at 3:10 am #2130220Brad
Resolved via other support thread noted above.
February 23, 2022 at 9:43 pm #2131400Elvin
StaffCustomer SupportThanks for letting us know. 😀
-
AuthorPosts
- You must be logged in to reply to this topic.