I want to display posts order by thumbnails i.e the post having thumbnails will display first and then display posts without thumbnail.
I found same situation on Stackoverflow here , But that doesn't work for me. Currently i am using directory+ theme in which i want to implement it.
I tried to make two loops, one loop will display post with thumbnail and second will display posts without thumbnail. But this doesnot work in case of pagination, as the post without thumbnail should on the last page
Here is the code
{var $itemQuery = array(
'post_type' => 'ait-item',
'posts_per_page' => $filterCountsSelected,
//'meta_key'=> '_thumbnail_id',
'tax_query' => array(
array(
'taxonomy' => 'ait-items',
'field' => 'term_id',
'terms' => $currentCategory->term_id
)
),
'paged' => $pagination,
)}
{customQuery as $query, $itemQuery}
{* Loop for categories with featured Image*}
{customLoop from $query as $post}
{if $post->image}
//Display post with thumbnail
{/if} //end of if
{/customLoop} //end of loop
{* Loop for categories without featured Image*}
{customLoop from $query as $post}
{if !$post->image}
//Display post without thumbnail
{/if} //end of if
{/customLoop} //end of loop
{includePart parts/pagination, location => pagination-below, max => $query->max_num_pages} //includes pagination
Edited Query 1:
{var $itemQuery = array(
'post_type' => 'ait-item',
'posts_per_page' => $filterCountsSelected,
'tax_query' => array(
array(
'taxonomy' => 'ait-items',
'field' => 'term_id',
'terms' => $currentCategory->term_id
)
),
'paged' => $pagination,
)}
{var $itemQuery['orderby'] = 'meta_value_num'}
{var $itemQuery['meta_query'] = array(
array(
'relation' => 'OR',
array(
'key' => '_thumbnail_id',
'compare' => 'NOT EXISTS'
),
array(
'key' => '_thumbnail_id',
'compare' => '!NOT EXISTS'
),
)
)}