Viewing 4 posts - 1 through 4 (of 4 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

    #1487603

    Thank you, it works perfectly

    #1487605

    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

Viewing 4 posts - 1 through 4 (of 4 total)
  • The topic ‘Grid layout – keep post on top’ is closed to new replies.