1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Find posts without featured image?

Discussion in 'Blogging' started by Nut-Nights, Jan 5, 2017.

  1. Nut-Nights

    Nut-Nights Jr. VIP Jr. VIP

    Joined:
    Jun 20, 2013
    Messages:
    5,604
    Likes Received:
    3,516
    Location:
    Hell
    Home Page:
    Any wordpress plugin for this ?
     
  2. trademysite

    trademysite Junior Member

    Joined:
    Oct 18, 2016
    Messages:
    110
    Likes Received:
    5
    Gender:
    Male
    Location:
    New Delhi
  3. outscrape

    outscrape Jr. VIP Jr. VIP

    Joined:
    Nov 23, 2016
    Messages:
    122
    Likes Received:
    79
    Did this work? I have a site where I could use this myself.
     
  4. trademysite

    trademysite Junior Member

    Joined:
    Oct 18, 2016
    Messages:
    110
    Likes Received:
    5
    Gender:
    Male
    Location:
    New Delhi
    In description it says "You can also see posts with no featured image at a glance."

    But from code side, wordpress manages images, documents any media by creating an attachment post for holding the information about that media and it's relation (if any) with other post/posts, which means you need sql query to find all posts without any images attached. To retrieve all posts without any image attached you can execute a query like this:

    SELECT DISTINCT(p.ID), p.post_title, p.post_content FROM `wp_posts` p
    LEFT JOIN wp_posts im ON p.ID = im.post_parent AND im.post_type = "attachment"
    WHERE p.post_status ='publish'
    AND p.post_type = "post"
    AND im.ID IS NULL
    AND p.post_content NOT REGEXP 'src=".*"'

    last code will remove posts which includes images inside it.
     
  5. trademysite

    trademysite Junior Member

    Joined:
    Oct 18, 2016
    Messages:
    110
    Likes Received:
    5
    Gender:
    Male
    Location:
    New Delhi
    or try this:

    $args = array(
    'meta_query' => array(
    array(
    'key' => '_thumbnail_id',
    'value' => '?',
    'compare' => 'NOT EXISTS'
    )
    ),
    );
    $new_query = new WP_Query( $args );


    in WP_Query()
    This must work.
     
  6. Nut-Nights

    Nut-Nights Jr. VIP Jr. VIP

    Joined:
    Jun 20, 2013
    Messages:
    5,604
    Likes Received:
    3,516
    Location:
    Hell
    Home Page:
    @trademysite that plugin didnt work and i already check that code on stack exchange, but i am not technical guy to use codes.

    I forget to mention my site got 20k + posts.
     
  7. trademysite

    trademysite Junior Member

    Joined:
    Oct 18, 2016
    Messages:
    110
    Likes Received:
    5
    Gender:
    Male
    Location:
    New Delhi
    Using the codes is very simple, just login to your mySQL and run the query.