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

    can’t imagine this really hasn’t been asked before, but i just couldn’t find anything..

    i’d like to have a ‘post slider’ element that only displays posts marked as ‘sticky’ – since there’s no setting in the UI i suppose i need to add a function, but where to hook it in?

    tia.

    #1429228

    Hey drahdiwaberl,

    Thank you for the inquiry.

    There is no option for this by default, but you can add the following code in the functions.php file to adjust the post slider query and display only sticky posts.

    function ava_sticky_posts_only($query)
    {
        if (is_page(123)) {
            $sticky = get_option('sticky_posts');
            if (!empty($sticky)) {
                $query['post__in'] = $sticky;
            }
        }
    
        return $query;
    }
    add_action('avia_post_slide_query', 'ava_sticky_posts_only', 10, 1);
    

    Adjust the ID or number in the is_page function with the ID of the page containing the post slider element.

    Best regards,
    Ismael

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