• prokur

    (@prokur)


    Dear WordPress gurus,

    Maybe some of you have idea how to get all posts and sort them in a way that ones with thumbnail go first. And all posts without thumbnail go to the end.
    After hours of research I came to the following examples, but they don’t help.

    $args = array('orderby' => array('_thumbnail_id' => 'DESC'));
    This example won’t sort

    $args = array('meta_key' => '_thumbnail_id', 'order' => 'DESC');
    This example excludes all posts without thumbail at all

Viewing 2 replies - 1 through 2 (of 2 total)
  • dxladner

    (@dxladner)

    you can do a condional type of tag and first check for posts with a thumbnail_id then display those only and then check for posts without a thumbnail_id and then print out those posts.

    for example using PHP

    wp post loop
    while have posts
    if(!empty(thumbnail_id)
    {
    then print out those posts
    }
    elseif (empty(thumbnail_id)
    {
    the print out those posts.
    }
    end posts loop

    Thread Starter prokur

    (@prokur)

    this is a good solution for small results, but it won’t work with many records and result pagination, because it requires to get all results into PHP first.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Showing posts with thumbnails first’ is closed to new replies.