WordPress.org

Forums

[resolved] post_count for only posts with thumbnail (5 posts)

  1. elkebirmed
    Member
    Posted 2 years ago #

    how to edit this condition in order to count only the posts with thumbnails?

    if ( $my_query->have_posts() && ( ( $my_query->post_count ) >= 3 ) )

  2. dhunink
    Member
    Posted 2 years ago #

  3. elkebirmed
    Member
    Posted 2 years ago #

    That's the conditional tag has_post_thumbnail, i need to get the number of posts with thumbnail

  4. dhunink
    Member
    Posted 2 years ago #

    Read the second line of my previous post.

    Two options:
    1. Edit the Query to only select posts which ID has occurence in the meta table with meta key as stated in the link.
    2. Loop through the results of the current query, for each post that has a thumbnail, count it.

    So (non-working code)

    $count = 0;
    foreach($posts as $post){
    if(has_tumbnail($post->ID)){ $count++; }
    }
  5. elkebirmed
    Member
    Posted 2 years ago #

    That's work, thank you dhunink

Topic Closed

This topic has been closed to new replies.

About this Topic