Plugin Support
David
(@diggeddy)
Hi there,
i believe that is the normal behaviour of a sticky post, WordPress doesn’t remove the original post from the loop
Thread Starter
dawund
(@dawund)
Plugin Support
David
(@diggeddy)
GB simple respects what WP post does with Sticky Posts. Which is to place a copy of the post at the top of the query. You can see this in a standard archive on a WP theme.
Its tricky but you could try this :
Add this PHP Snippet to your site:
add_filter( 'generateblocks_query_loop_args', function( $query_args, $attributes ) {
$url = $_SERVER['REQUEST_URI'];
$query_string = parse_url($url, PHP_URL_QUERY);
parse_str($query_string, $query_params);
$last_param_value = end($query_params);
// check URL for page query
// find the block with my-class-name
if (
$last_param_value > 1 &&
! empty( $attributes['className'] ) &&
strpos( $attributes['className'], 'has-sticky' ) !== false &&
! is_admin()
) {
var_dump('shit');
// get the sticky posts
$sticky_posts = get_option( 'sticky_posts' );
// exclude the sticky posts
return array_merge( $query_args, array(
'post__not_in' => $sticky_posts,
) );
}
return $query_args;
}, 10, 2 );
Then select the Grid Block inside the Query Loop and give it an Advanced > Additional CSS Class of: has-sticky
The code will check the URL for its last parameter and if its greater than 1 it should pass the $sticky_posts into the query loops post__not_in param.
It may work.
Let me know
Thread Starter
dawund
(@dawund)
Hello David,
thank you for the answer. I tried the code but first it disables the original just for the first time and second the posts are not moving. The 13th post of page one will not be moved to page two as the first post.
Plugin Support
David
(@diggeddy)
Unfortunately i do not have a solution for this today.
What you’re seeing is the expected behaviour. WordPress core doesn’t remove the original post from the loop. You will see the same result in a core WP Themes archive pages, and in the core Query Loop block.
The code i provided above, worked on one of my installs, but the conditional checks aren’t very robust and would most likely fail if there are more than one query loop on the page. And therefore not a viable solution.
I am not sure its possible that we can change this behaviour, but i will note it as possible future feature.
Today, if you want to use Sticky Posts as a feature post and avoid the duplicate, then you would need to use 2 x Query Loops. Loop 1 = just the sticky post, Loop 2 = all posts excluding stickies. You of course would need to change your design to accommodate that change.
Hi there! We haven’t heard back from you for a while now so we’re going to go ahead and set this topic as resolved. Feel free to reply if you need any more help with anything else GP-theme related.