Hi,
using the grid layout for the blog, the “keep post on top” doesn’t work, is there a fix for this?
Thank you
Hey Uli,
Thank you for the inquiry.
Yes, unfortunately, the grid layout doesn’t support sticky posts by default. This is still possible, but you’ll need to add the following modification to the functions.php file.
// include sticky posts in grid layout
add_filter('avia_post_slide_query', function ($query, $params) {
$sticky_posts = get_option('sticky_posts');
if (empty($sticky_posts) || !is_array($sticky_posts)) {
return $query;
}
$sticky_posts = array_map('intval', $sticky_posts);
if (!empty($query['post__in'])) {
$query['post__in'] = array_unique(array_merge($sticky_posts, $query['post__in']));
} else {
$posts = get_posts([
'post_type' => $query['post_type'],
'post_status' => 'publish',
'posts_per_page' => $query['posts_per_page'],
'orderby' => $query['orderby'],
'order' => $query['order'],
'post__not_in' => $sticky_posts,
'fields' => 'ids',
]);
$query['post__in'] = array_merge($sticky_posts, $posts);
}
$query['orderby'] = 'post__in';
return $query;
}, 10, 2);
Best regards,
Ismael
Thank you, it works perfectly
Hi,
Great, I’m glad that Ismael could help you out. Please open a new thread if you should have any further questions or problems.
Best regards,
Rikard