I want to discuss this possible solution.
For a given category ID (5) we do:
1. Clear primary category for all posts in this category.
2. Set this category as the primary category for all posts.
So, for example, if 100 articles are attached to the category 5 (and others), this category will be the primary for all of this 100 posts.
Solution:
CLEAR PRIMARY CATEGORY:
DELETE
FROM wp_postmeta
WHERE post_id IN (
SELECT ID
FROM wp_posts
WHERE ID IN (
SELECT object_id
FROM wp_term_relationships
WHERE term_taxonomy_id = 5
)
) and meta_key = '_yoast_wpseo_primary_category'
SET CATEGORY 5 AS THE MAIN CATEGORY FOR ALL POSTS WICH ARE ATTACHED TO THIS CATEGORY.
INSERT INTO wp_postmeta(post_id,meta_key,meta_value)
SELECT ID, '_yoast_wpseo_primary_category', 5 FROM wp_posts WHERE ID IN (SELECT object_id FROM wp_term_relationships WHERE term_taxonomy_id = 5)
Make sure you:
1. Backup your database before any update.
2. Change the 5 to the ID of your desired main category.
What do you think about this solution?