jensmolsson
Member
Posted 1 year ago #
Hello,
Do anyone know if it is possible with using query_posts to priority/order by posts that have thumbnail?
I have manage to sort out the once that have thumbnail but then I do not get the once that does not. So I still want posts that have thumbnail and the once that does not just that the once that have thumbnail should be priority.
Thanks!
No - there's no parameter for post_thumbnail.
jensmolsson
Member
Posted 1 year ago #
Thanks for your answer Esmi.
Is there a alternative way for doing this?
Thanks!
You have to grab the post that you want and then run the results through some custom code that sorts the returned array of posts based on whether they have a post thumb or not.
jensmolsson
Member
Posted 1 year ago #
Thanks Esmi. I will go for that :)
jensmolsson
Member
Posted 1 year ago #
Here is the solution I used for this issue:
//Post per page
$post_per_page = 10;
//Get all that have thumbnail
query_posts($query_string."&posts_per_page=".$post_per_page."&meta_key=_thumbnail_id&orderby=meta_value&order=DESC");
$posts = $wp_query->post_count;
//Loop
if ( have_posts() ) : while ( have_posts() ) : the_post();
//Content
endwhile; endif;
//Get the rest
if($posts<$post_per_page) {
$showPoster = $post_per_page-$posts;
query_posts($query_string."&posts_per_page=".$showPoster."&order=DESC");
//Loop
if ( have_posts() ) : while ( have_posts() ) : the_post();
//Content
endwhile; endif;
}