If you want to Yoast add focus keyword to all posts that don’t already have one, this SQL query does it in a single bulk operation – setting each post’s Yoast focus keyphrase to its own title wherever the field is currently empty. It’s the fastest way to clear a dashboard full of red “no focus keyphrase” warnings after a large import, migration, or content audit.
Table of Contents
Why You’d Need to Bulk-Set Focus Keywords
Yoast SEO stores the focus keyphrase for every post, and its dashboard flags any post missing one. That’s fine for a handful of posts, but if you’ve just imported hundreds of posts from another platform, migrated a site, or inherited a blog that never had focus keywords set, editing each one by hand isn’t realistic. Running a single SQL query to Yoast add focus keyword to all posts missing one gets you to a clean baseline instantly – you can always refine individual keywords later, but starting from the post title beats leaving the field empty.
In WordPress, Yoast SEO stores metadata, including focus keywords, in the wp_postmeta table. Each post’s metadata is identified by the post_id that links to the wp_posts table. The meta key for Yoast focus keywords is _yoast_wpseo_focuskw.
Here’s an SQL query to achieve this:
-- Update Yoast focus keywords with the title of the post if not already set
INSERT INTO wp_postmeta (post_id, meta_key, meta_value)
SELECT p.ID, '_yoast_wpseo_focuskw', p.post_title
FROM wp_posts p
LEFT JOIN wp_postmeta pm
ON p.ID = pm.post_id AND pm.meta_key = '_yoast_wpseo_focuskw'
WHERE p.post_type = 'post'
AND p.post_status = 'publish'
AND pm.post_id IS NULL;
Yoast Add Focus Keyword to All Posts: How the Query Works
wp_posts p: This selects posts from thewp_poststable.LEFT JOIN wp_postmeta pm: Joins thewp_postmetatable where themeta_keyis_yoast_wpseo_focuskw(the Yoast focus keyword) to check if the focus keyword exists for the post.WHERE pm.post_id IS NULL: This ensures the query only selects posts that do not have a Yoast focus keyword set.p.post_title: Inserts the post title as the focus keyword.
How to Run This Query
You have a few options depending on your setup:
- phpMyAdmin or Adminer: paste the query into the SQL tab for your WordPress database and run it directly.
- WP-CLI: if you manage the server over SSH,
wp db query "PASTE_QUERY_HERE"runs it against the active WordPress database without needing a GUI. - Hosting control panel database tool: most managed hosts (cPanel, Plesk, etc.) expose a database query interface that works the same way as phpMyAdmin.
Verifying It Worked
After running this query, posts without focus keywords will have their titles set as the focus keyword in Yoast SEO. In the WordPress admin, go to Posts, use the filter dropdown, and select “Posts without focus keyphrase” – the list should now be empty, or close to it. [I’m not sure how the re-scoring is triggered, but I went to Posts > filter by > and selected “posts without keywords” – I then manually edited a couple and clicked save, and the rest were updated automatically.]
Worth noting: a focus keyword copied straight from the post title is a starting point, not a finished keyword strategy – it’s still worth going back and setting a proper, search-intent-matched keyphrase for your highest-traffic posts. If you’re also dealing with Yoast and a block theme fighting over the title tag itself, that’s a separate (and more annoying) issue – see my post on duplicate title tags with Yoast SEO and block themes for the fix.
Additional Notes:
- Make sure to back up your database before running this query.
- Modify
wp_if your database uses a different table prefix.

Leave a Reply
You must be logged in to post a comment.