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 2, 2022 at 7:05 pm #2103368
Brad
Create CPT named Photography.
Trying to limit / change number of posts on archive page to 3 ( for testing )Code below works but skips over all the GenerateBlocks customization; looks like it defaults back to archive.php without using GP elements – header, elements – block – content template. Etc.
Note: in child theme I did create archive-photography.php, content-photography.php, single-photography.php
Found this code from another GP support thread and amended it to target archive post type.
https://generatepress.com/forums/topic/limit-the-number-of-post/
function j66co_photography_posts_per_page($query) {
if (is_post_type_archive( ‘photography’ )) {
$query->set(‘posts_per_page’, 3);
}
}add_action(‘pre_get_posts’, ‘j66co_photography_posts_per_page’);
Thoughts? Thank for help in advance.
February 2, 2022 at 10:52 pm #2103500Elvin
StaffCustomer SupportHi Brad,
Try adding this snippet:
add_filter( 'generate_elements_custom_args', function( $args ) { $args['suppress_filters'] = true; return $args; } );This should make the Block Element – Content Template work with pre_get_posts.
February 3, 2022 at 12:04 am #2103536Brad
No. Didn’t work. I’m using code snippet plugin right now for testing. It’s set at priority 10. Both together as follows:
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);
}
}add_action(‘pre_get_posts’, ‘j66co_photography_posts_per_page’);
February 3, 2022 at 12:56 am #2103557Elvin
StaffCustomer SupportStrange. I’ve used the exact code and it seems to be working as you can see on this loose replication.
http://elvin.wppluginsupport.net/photographyThis sandbox site is using the same code you’ve shared as shown here –
https://share.getcloudapp.com/BludboLeIf you check the page, the Block content template is applied AND there are only 3 posts per page on the archive.
Perhaps there are other codes or plugins causing conflicts.
Can you let us have temporary backend access to take a look? You can use the private information text field for this –
https://docs.generatepress.com/article/using-the-premium-support-forum/#private-informationFebruary 3, 2022 at 1:15 am #2103565Brad
Just saw reply. Create admin user. Info in private box. Thanks for taking a look.
February 3, 2022 at 1:20 am #2103568Elvin
StaffCustomer SupportAh. I missed one important context.
I see that you have a child theme. Can you disable the child theme and see if it works?
The child theme’s template is likely overriding the effects of the Block element – content template as child theme’s template serve the same purpose as what Block element – Content template does.
February 3, 2022 at 2:33 pm #2104452Brad
Just seeing this child theme reply. Saw you login last night. Did you have any luck? Want me to disable child theme? I’m afraid that will break the whole site.
February 3, 2022 at 7:33 pm #2104585Elvin
StaffCustomer SupportTry to at least remove
archive-photography.phpas that’s most likely the specific one that may have caused the issue.February 3, 2022 at 8:13 pm #2104604Brad
No. Renamed it. Didn’t work.
February 3, 2022 at 9:03 pm #2104650Elvin
StaffCustomer SupportJust seeing this child theme reply. Saw you login last night. Did you have any luck? Want me to disable child theme? I’m afraid that will break the whole site.
In this context, can we clone the site to a staging site? So we can disable a few things without worry about the live site breaking.
We’ll likely have to disable the child theme and plugins and enable them one by one to be sure which one is causing the issue.
February 3, 2022 at 10:14 pm #2104689Brad
Sure. It’s my dev server domain. I’ve been up since 3a.,it’s 9p now. Really tired. I’ll hit it up tomorrow and comment back. Next couple days / whenever you have a chance to take a look a staging that would be cool.
I’ll deactivate plug-ins one by one on staging after creating staging first and comment back. Just give me a day or so.
February 3, 2022 at 10:17 pm #2104690Elvin
StaffCustomer SupportCopy. You can bump this thread to let us know when it’s up. 🙂
February 12, 2022 at 9:38 am #2115836Brad
Hey Elvin / Team GeneratePress
I finally got a chance to clone my dev site to staging. Login credentials are in private section if still open to taking a look.
Background
As suggested in your last comment from a few days ago, I deactivated the child theme. No luck solving problems though.___________
Issue:
Trying to reduce number of posts from default 10 to 3 for testing in the “photography” CPT (and eventually “showcase” CPT).
____________
Result:
a.
It works but all Generateblocks Elements Header Hero images / Content Template layouts get disregarding.b.
Pagination stops working. Page 2.. opps not found.c.
Mobile menu stopped working on pages with var dump code.Code:
function j66co_photography_posts_per_page($query) {
if (is_post_type_archive( ‘photography’ )) {
$query->set(‘posts_per_page’, 3);
}
}add_action(‘pre_get_posts’, ‘j66co_photography_posts_per_page’);
____________
What’s set in GB Elements?
Locations to display the Content Templates / Headers are all set to the correct targets (all category archives) etc.
A couple of elements won’t allow drop down; hence I tried the filter below. Problem. Couldn’t located ID of category archive / CPT archive pages. Amended var dump code into archive-photography.php / archive-showcase.php
int(0) returned
Code:
$posts = get_posts( );
echo ‘'; var_dump(get_queried_object_id()); echo '
‘;
die( );////////////////
Issue:
Trying to have CPT show up in categories archive.
Result:
Same as above. Got it to work but it’s not using the (a.) The Generateblocks Elements Header Hero images / Content Template layouts get disregarding.
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’ );////////////////
Thanks for your assistance in helping me unwind this. I do sincerely appreciate it.
Brad
February 13, 2022 at 8:11 pm #2117273Elvin
StaffCustomer SupportCan you keep the child themes and ALL plugins deactivated(except GP Premium and CPT UI)?
So we can find a base/control version where everything works and we’re sure it has no conflict. (similar to the working example here – http://elvin.wppluginsupport.net/photography)
We’re close. We just need to figure out what’s messing w/ the code as I’m sure it works. The site I’ve linked actually uses the exact code your site uses – https://share.getcloudapp.com/Apuxo7kL
If you have multiple snippets w/ different instances of pre_get_posts, I think we can re-write them all into just 1 filter instead of having multiple instances. (I think you have 2 on the code snippets)
February 13, 2022 at 9:32 pm #2117313Brad
Sure. Sincere thanks for taking a look. Feel free to do whatever you want to the staging site!
Deactivate plugins, etc. I’m away from desktop right now on iphone.
-
AuthorPosts
- You must be logged in to reply to this topic.