- This topic has 35 replies, 3 voices, and was last updated 4 years, 3 months ago by
Tom.
-
AuthorPosts
-
December 15, 2021 at 6:52 am #2049871
Pete
No, in the general settings for wp, the Reading settings, number of blog posts to show.
December 16, 2021 at 2:47 pm #2051428Tom
Lead DeveloperLead DeveloperHi there,
Try adding this:
add_filter( 'generate_elements_custom_args', function( $args ) { $args['suppress_filters'] = true; return $args; } );It should tell Elements to ignore the
pre_get_postsfilter.Let us know 🙂
December 16, 2021 at 4:30 pm #2051482Pete
No joy unfortunately Tom.
December 17, 2021 at 8:44 pm #2052595Tom
Lead DeveloperLead DeveloperCan you confirm that the problem goes away if you remove that
pre_get_postsfilter?If it does, can you share it here so I can take a closer look at exactly what you’re adding?
Thanks!
December 17, 2021 at 10:51 pm #2052633Pete
When I remove the code from the original question, the problem goes away.
December 18, 2021 at 9:42 pm #2053396Tom
Lead DeveloperLead DeveloperIs this the exact code?:
add_action( 'pre_get_posts', 'sk_query_offset', 1 ); function sk_query_offset( &$query ) { // Before anything else, make sure this is the right query... if ( ! ( $query->is_category('clubs') || is_main_query() ) ) { return; } // First, define your desired offset... $offset = -3; // Next, determine how many posts per page you want (we'll use WordPress's settings) $ppp = get_option( 'posts_per_page' ); // Next, detect and handle pagination... if ( $query->is_paged ) { // Manually determine page query offset (offset + current page (minus one) x posts per page) $page_offset = $offset + ( ( $query->query_vars['paged']-1 ) * $ppp ); // Apply adjust page offset $query->set( 'offset', $page_offset ); } else { // This is the first page. Set a different number for posts per page $query->set( 'posts_per_page', $offset + $ppp ); } } add_filter( 'found_posts', 'sk_adjust_offset_pagination', 1, 2 ); function sk_adjust_offset_pagination( $found_posts, $query ) { // Define our offset again... $offset = -3; // Ensure we're modifying the right query object... if ( $query->is_category('clubs') && is_main_query() ) { // Reduce WordPress's found_posts count by the offset... return $found_posts - $offset; } return $found_posts; }If so, can you comment out the
add_actionline and see if it fixes it? If not, can you try commenting out theadd_filterline?Just trying to narrow down exactly which function is causing the conflict.
Thanks!
December 20, 2021 at 10:43 pm #2055184Pete
Yes, the exact code, and no luck with both fixes.
December 21, 2021 at 8:35 pm #2056287Tom
Lead DeveloperLead DeveloperSo the issue only goes away if you remove both functions? Not only one of them?
December 22, 2021 at 3:52 pm #2057166Pete
Ok…
1. I’ve added your filter
2. removingadd_actionstops the solution, but also stops(doesn’t create) the problem – no difference
3. removingadd_filtergives me the solution (different paged) but also creates the problem – no map or dropdown.add_filter( 'generate_elements_custom_args', function( $args ) { $args['suppress_filters'] = true; return $args; } ); add_action( 'pre_get_posts', 'sk_query_offset', 1 ); function sk_query_offset( &$query ) { // Before anything else, make sure this is the right query... if ( ! ( $query->is_category('clubs') || is_main_query() ) ) { return; } // First, define your desired offset... $offset = -3; // Next, determine how many posts per page you want (we'll use WordPress's settings) $ppp = get_option( 'posts_per_page' ); // Next, detect and handle pagination... if ( $query->is_paged ) { // Manually determine page query offset (offset + current page (minus one) x posts per page) $page_offset = $offset + ( ( $query->query_vars['paged']-1 ) * $ppp ); // Apply adjust page offset $query->set( 'offset', $page_offset ); } else { // This is the first page. Set a different number for posts per page $query->set( 'posts_per_page', $offset + $ppp ); } } add_filter( 'found_posts', 'sk_adjust_offset_pagination', 1, 2 ); function sk_adjust_offset_pagination( $found_posts, $query ) { // Define our offset again... $offset = -3; // Ensure we're modifying the right query object... if ( $query->is_category('clubs') && is_main_query() ) { // Reduce WordPress's found_posts count by the offset... return $found_posts - $offset; } return $found_posts; }December 23, 2021 at 9:20 pm #2058155Tom
Lead DeveloperLead DeveloperJust to confirm, this is the issue we’re trying to debug, correct?: https://generatepress.com/forums/topic/different-number-of-posts-on-paged-archives/#post-2048561
If so, which one of the above 3 methods fixed the Hooks not displaying? Removing
add_actionoradd_filter?I ask just so we can pinpoint which function is causing the Hooks issue. Then we might be able to tweak the problem function so it ignores Elements.
December 23, 2021 at 10:47 pm #2058183Pete
Just to confirm, this is the issue we’re trying to debug, correct?: https://generatepress.com/forums/topic/different-number-of-posts-on-paged-archives/#post-2048561
Correct
If so, which one of the above 3 methods fixed the Hooks not displaying? Removing add_action or add_filter?
None of the above 3 fixed the Hooks not displaying. The original post solved the different number of posts on different pages BUT nothing has solved the problem of the Hooks not displaying.
I’ll make a screencast to show you
December 24, 2021 at 8:30 pm #2058861Tom
Lead DeveloperLead DeveloperOh, so the Hooks not displaying issue wasn’t caused by the original different number of posts solution? I though that the solution itself was causing the Hooks to not appear.
December 24, 2021 at 8:57 pm #2058869Pete
Youtube explanation
December 26, 2021 at 9:00 pm #2060199Tom
Lead DeveloperLead DeveloperThanks for the video!
It looks like the first function is causing the issue.
Let’s try this as the entire snippet instead of what you have now:
add_action( 'pre_get_posts', 'sk_query_offset', 1 ); function sk_query_offset( &$query ) { if ( is_admin() ) { return; } // Before anything else, make sure this is the right query... if ( ! ( $query->is_category('clubs') || is_main_query() ) ) { return; } // Don't do anything to Elements. if ( 'gp_elements' === $query->get( 'post_type' ) ) { return; } // First, define your desired offset... $offset = -3; // Next, determine how many posts per page you want (we'll use WordPress's settings) $ppp = get_option( 'posts_per_page' ); // Next, detect and handle pagination... if ( $query->is_paged ) { // Manually determine page query offset (offset + current page (minus one) x posts per page) $page_offset = $offset + ( ( $query->query_vars['paged']-1 ) * $ppp ); // Apply adjust page offset $query->set( 'offset', $page_offset ); } else { // This is the first page. Set a different number for posts per page $query->set( 'posts_per_page', $offset + $ppp ); } } add_filter( 'found_posts', 'sk_adjust_offset_pagination', 1, 2 ); function sk_adjust_offset_pagination( $found_posts, $query ) { if ( is_admin() ) { return; } // Define our offset again... $offset = -3; // Ensure we're modifying the right query object... if ( $query->is_category('clubs') && is_main_query() ) { // Reduce WordPress's found_posts count by the offset... return $found_posts - $offset; } return $found_posts; }Let me know 🙂
December 27, 2021 at 3:12 am #2060392Pete
Thanks Tom. that did the trick. Thanks for persevering. Happy new year!
-
AuthorPosts
- You must be logged in to reply to this topic.