meta_query keys and sticky posts

The problem is that the code works but when i make a post sticky it doesn’t appear at first.

The function of the code:
It only shows posts that have a thumbnail or a slideshow image.

<?php

$args = array(  'numberposts'  => 5,
                'meta_query'   => array(
                    'relation' => 'OR',
                    array(
                        'key'     => '_thumbnail_id',
                        'compare' => '!=',
                        'value'   => ''
                    ),
                    array(
                        'key'     => 'slideshow_image',
                        'compare' => '!=',
                        'value'   => ''
                    )
                )
            );


$my_posts = get_posts( $args );
global $post;
foreach( $my_posts as $post ) : setup_postdata($post);

?>

<?php the_post_thumbnail('thumb-small'); ?>
<a href="<?php the_permalink(); ?>">
    <?php the_title(); ?>
</a>

<?php
endforeach;
wp_reset_postdata();
?>

Related posts

1 comment

  1. get_posts() is a rather generic wrapper for retrieving set of posts and just that. As such it purposely unmakes some of the arguments typical for loops.

    Specifically it ignore stickies:

    $r['ignore_sticky_posts'] = true;
    

    So if you want more loop-like behavior you should be using instance of WP_Query object instead.

Comments are closed.