Query all WordPress posts in MySQL not having a Yoast SEO meta description

Home » Web applications » WordPress » Query all WordPress posts in MySQL not having a Yoast SEO meta description

If you just started using Yoast SEO it’s sometimes nice to know which posts don’t have a meta description yet. Knowing this, you can add the description which is good for your SEO results. Here is a query you can use to query all posts in WordPress not having a Yoast SEO meta description yet. You can run this on your MySQL prompt or in phpMyAdmin.

Here is a query you can use to query all posts in WordPress not having a Yoast SEO meta description yet. You can run this on your MySQL prompt or in phpMyAdmin.

SELECT p.ID, p.post_title, pm.meta_key, pm.meta_value
  FROM wp_posts p
  LEFT JOIN wp_postmeta pm ON p.ID = pm.post_id AND pm.meta_key = '_yoast_wpseo_metadesc'
  WHERE p.post_type in ('post', 'page')
  AND p.post_status='publish'
  AND pm.meta_key IS NULL;

The SQL query above lists all posts and pages not having a Yoast SEO meta description, because we look at WHERE ... pm.meta_key IS NULL. If you want to inspect all meta description, change it to IS NOT NULL, like this:

SELECT p.ID, p.post_title, pm.meta_key, pm.meta_value
  FROM wp_posts p
  LEFT JOIN wp_postmeta pm ON p.ID = pm.post_id AND pm.meta_key = '_yoast_wpseo_metadesc'
  WHERE p.post_type in ('post', 'page')
  AND p.post_status='publish'
  AND pm.meta_key IS NOT NULL;

This may come in handy to when you want to bulk review the meta descriptions of all your posts and pages.

Conclusion

Run a specific SQL query in the MySQL prompt or phpMyAdmin to quickly identify WordPress posts missing Yoast SEO meta descriptions. This query highlights posts without descriptions, making it easy to spot gaps. To find posts with meta descriptions, simply adjust the query to use ‘IS NOT NULL’. This approach streamlines the process of reviewing and optimizing meta descriptions in bulk.

One-time donation

Please take a second to support Sysadmins of the North and donate, your generosity helps!

Jan Reilink
Jan Reilink

In my day to day work, I’m a systems administrator – DevOps / SRE and applications manager at Embrace – The Human Cloud. At Embrace we develop, maintain and host social intranets for our clients. Provide digital services and make working more efficient within various sectors.

Want to support me and donate? Use this link: https://www.paypal.com/paypalme/jreilink.

Articles: 161