WordPress.org

Ready to get started?Download WordPress

Forums

Priority posts that have thumbnail (6 posts)

  1. 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!

  2. esmi
    Theme Diva & Forum Moderator
    Posted 1 year ago #

    No - there's no parameter for post_thumbnail.

  3. jensmolsson
    Member
    Posted 1 year ago #

    Thanks for your answer Esmi.
    Is there a alternative way for doing this?

    Thanks!

  4. esmi
    Theme Diva & Forum Moderator
    Posted 1 year ago #

    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.

  5. jensmolsson
    Member
    Posted 1 year ago #

    Thanks Esmi. I will go for that :)

  6. 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;
    
    }

Topic Closed

This topic has been closed to new replies.

About this Topic