• Resolved outliners

    (@outliners)


    Hi there, love the new function to choose the primary category. With more than 800 products in our webshop, is it possible to bulk change the primary category for products?

Viewing 7 replies - 1 through 7 (of 7 total)
  • I was looking for something like this too. I bulk added my products and they have 1 parent category, and then multiple sub categories and I want the lowest one to become the primary. e.g. “Women”->”Shoes”->”Boots (primary)”

    I too have this question. Have a clients site with over 1200 posts and each post having multiple categories assigned to it and want to bulk set the primary category. Anyone figures out a way to do this?

    • This reply was modified 7 years, 9 months ago by Jason.

    Hello!

    I’m also interested on this topic. It would be great to set primary category for all posts / products in the “bulk edit” or maybe a “set this category as primary” when you edit the category.

    I dont’ know hot to do this, but it would be great … ??

    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?

    I’d be very interested in this as well got a site in development that has over 1000 products in and we need to set the primary category of most of them and don’t really want to have to do it manually.

    I found a bug in my queries. This doesn’t work properly.. Do not use in a production database.

    I’m working on solve it…

    Sorry!

    Is a bit complicated when it comes to several products. That tambine was my problem thanks for solving it

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Bulk change primary category’ is closed to new replies.