Home › Forums › Support › Change post per page – custom post type archive page. Element templates skipped
- This topic has 34 replies, 2 voices, and was last updated 4 years, 1 month ago by
Elvin.
-
AuthorPosts
-
February 13, 2022 at 9:38 pm #2117317
Elvin
StaffCustomer SupportI replied to one of your topics here
https://generatepress.com/forums/topic/any-advanced-docs-elements-content-template-apply-to-post-w-term-location/page/2/#post-2117287It may be related to this as well.
February 13, 2022 at 9:53 pm #2117329Brad
Thanks. Yeah. Same related issue. The GenerateBlocks Elements Content Template layouts get bypassed for some reason when I’ve added a couple different functions to change things.
1.
Post per page for CPT2.
Add CPT to categoriesFebruary 13, 2022 at 10:08 pm #2117342Elvin
StaffCustomer SupportStrange,
I’ve just tested this as well on this test category –
http://elvin.wppluginsupport.net/category/testYou can inspect the page and see that some posts now have
type-showcaseindicatingshowcaseCPT while the content template is intact:
https://share.getcloudapp.com/mXuJ49AYFor reference, the setup of the sandbox site is basically:
– WordPress 5.9
– Latest versions of GP Premium and GeneratePress
– No child theme or other plugins active. (Only GenerateBlocks and CPT UI active)If you can replicate this setup and see it working for the purpose of having a known working control version, we can work our way through the plugins. (Enabling 1 by 1 to see which is the issue.)
If it’s not the plugins, we can try re-saving permalinks and then go through the child theme.
February 14, 2022 at 9:57 am #2118320Brad
Ok. I really didn’t want to go to Wp 5.9 but I went ahead and did it (I’ve got a backup).
SITE
www . stagingblocks-01.j66labs. co
Parent GP theme active
All plugins deactivated except GP Pro and GB Pro
All snippets turned offPagination issue: fixed
The problem was a plug-in for custom permalinks for CPT.Main issues (gb elements content template layout disappearing once adding scrips) were still present. I deactivate in a somewhat logical order, although turned scrips off first. Probably should of left them on, turn them off last.
February 14, 2022 at 8:10 pm #2118868Elvin
StaffCustomer SupportMain issues (gb elements content template layout disappearing once adding scrips) were still present. I deactivate in a somewhat logical order, although turned scrips off first. Probably should of left them on, turn them off last.
With this, the procedure for debugging is disabling ALL Block elements and enable them one by one and see if a one’s display rule location conflicts with another.
I see you had almost 2 pages worth of elements. It may be worth checking if some of them have overlapping display rules. 😀
February 14, 2022 at 8:42 pm #2118875Brad
Ok. I didn’t realize that was an option. I’ll try that next. First though I need to reactivate bare minimum plugins, CPT UI and ACF Pro plug-ins though, yes to populate posts?
February 14, 2022 at 9:35 pm #2118887Elvin
StaffCustomer SupportCPT UI and ACF Pro plug-ins though, yes to populate posts?
That’s right. Actually, you must keep them on for this.
Else, you probably won’t be able to test the archives as CPT UI generates it when you made the CPT.
February 15, 2022 at 2:27 am #2119117Brad
Quick lame question. How do you turn off element? Put them in draft mode, throw in trash then restore?
February 15, 2022 at 2:32 am #2119124Elvin
StaffCustomer SupportQuick lame question. How do you turn off element? Put them in draft mode, throw in trash then restore?
Putting it to “Draft” will do.
February 17, 2022 at 2:18 pm #2123336Brad
Ok. Went through as suggested on staging block-01 site. Strange. Header came back on “photography” category but that’s it. Now I have bare minimum elements running with required plugins for site to work. Same issues though.
Something is conflicting to not allow GenerateBlocks Elements to show once the “post limit per cpt” script is add as well as the “add category support to cpt”.
Any suggestions from here?
February 17, 2022 at 9:53 pm #2123605Elvin
StaffCustomer SupportI see you have multiple pre_get_posts snippets on your site. https://share.getcloudapp.com/12u0YA2n
We should maintain just 1 and do all the conditions on that 1 pre_get_post filter so it’s easier to follow.
I did some edits on the code and the “— Limit Post Per Page — CPT photography — 220213″ snippet and you can see that it works now.
I basically merged the conditions of this one and CPT showcase as well so you only have to maintain 1 for both but I suggest doing the same for the snippet ” — Show cpt in categories — ” as it’s redundant.
See it working here – https://share.getcloudapp.com/yAukNDdr
You can see that it now displays 3 posts per page WHILE maintaining the block element content template. 🙂
February 17, 2022 at 11:09 pm #2123655Brad
Sincere thank you!!!!
Ok. Interesting and strange. I think function number 1 purple in my screenshot adds support to include CPT in categories by default.
I had a function to add this. Possibly that was screwing everything up plus I had the purple number 1 filter listed three times.
https://www.dropbox.com/s/2e7ol6rkqk6lk5y/Post-per-page.jpg?dl=0
Now I have the following with no function to add category support to CPT.
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’ ) && empty( $query->query_vars[‘suppress_filters’] ) ) {
$query->set(‘posts_per_page’, 3);
}if( ( is_category() || is_tag() ) && empty( $query->query_vars[‘suppress_filters’] ) ) {
$query->set( ‘post_type’, array( ‘post’,’photography’) );return $query;
}
}
add_action(‘pre_get_posts’, ‘j66co_photography_posts_per_page’, 99, 1);function j66co_showcase_posts_per_page($query) {
if ( is_post_type_archive( ‘showcase’ ) && empty( $query->query_vars[‘suppress_filters’] ) ) {
$query->set(‘posts_per_page’, 4);
}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_showcase_posts_per_page’, 99, 1);February 17, 2022 at 11:18 pm #2123663Elvin
StaffCustomer SupportNo need to put them in separate
add_action(). We can do with just one.Example:
function j66co_photography_posts_per_page($query) { /* assign post_per_page to archives with Block Element - Content Template */ if ( empty( $query->query_vars['suppress_filters'] ) ) { if( is_post_type_archive( 'photography' ) ){ /* PPP 3 for Photography */ $query->set('posts_per_page', 3); } elseif ( is_post_type_archive( 'showcase' ) ){ /* PPP 3 for Showcase */ $query->set('posts_per_page', 4); } } /* Add CPTs to category and tag archives */ if( ( is_category() || is_tag() ) && empty( $query->query_vars['suppress_filters'] ) ) { $query->set( 'post_type', array( 'post', 'photography', 'showcase') ); return $query; } } add_action('pre_get_posts', 'j66co_photography_posts_per_page', 99, 1);The array in
$query->set( 'post_type', array( 'post', 'photography', 'showcase') );lets you add in more CPT to the cat or tag archive.February 18, 2022 at 12:47 am #2123710Brad
Yeah IDK why but the more efficient code doesn’t work.
IDK what’s going on. Here’s a link to the main dev site working know with just my inefficient code below:
https://blocks-01.j66labs.co/showcase/
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’ ) && empty( $query->query_vars[‘suppress_filters’] ) ) {
$query->set(‘posts_per_page’, 3);
}if( ( is_category() || is_tag() ) && empty( $query->query_vars[‘suppress_filters’] ) ) {
$query->set( ‘post_type’, array( ‘post’,’photography’) );return $query;
}
}
add_action(‘pre_get_posts’, ‘j66co_photography_posts_per_page’, 99, 1);function j66co_showcase_posts_per_page($query) {
if ( is_post_type_archive( ‘showcase’ ) && empty( $query->query_vars[‘suppress_filters’] ) ) {
$query->set(‘posts_per_page’, 4);
}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_showcase_posts_per_page’, 99, 1);February 18, 2022 at 1:10 am #2123727Elvin
StaffCustomer SupportThis URL is not a category page. It’s an archive specifically for the CPT Showcase so only cpt with name of
showcasewill display here.Can you link us to a category page w/ the supposed mix of cpts?
-
AuthorPosts
- You must be logged in to reply to this topic.