Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #1487546

    Hi,
    using the grid layout for the blog, the “keep post on top” doesn’t work, is there a fix for this?
    Thank you

    #1487587

    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

Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.