WordPress:如何将没有类别的帖子添加到类别中

时间:2014-11-04 13:59:08

标签: wordpress

我的WordPress中有一些帖子没有类别,它上面有2000篇文章,所以我需要将这篇文章添加到名称为"新闻"通过SQL

3 个答案:

答案 0 :(得分:0)

这应该有效:

UPDATE wp_term_relationships SET term_taxonomy_id = '3' WHERE term_taxonomy_id = '1';

3是类别"新闻"的ID,如果它与您不同,您可能需要更改它。 1是"未分类"的类别ID,因此以上内容应将1(未分类)的所有帖子ID更改为3(新闻)

编辑尝试:

 UPDATE wp_term_relationships SET term_taxonomy_id = '3' WHERE term_taxonomy_id = '';

答案 1 :(得分:0)

我没有找到这个问题的答案,所以也许对某人会有帮助。 您可以尝试使用此代码,但改为777-添加类别ID

INSERT IGNORE INTO wp_term_relationships
(object_id, term_taxonomy_id, term_order)
SELECT 
    wp_posts.ID as object_id,
    777 as term_taxonomy_id,
    0 as term_order
FROM    wp_posts
LEFT JOIN 
        wp_term_relationships rel
ON      wp_posts.ID = rel.object_id 
LEFT JOIN 
        wp_term_taxonomy tax
ON      tax.term_taxonomy_id = rel.term_taxonomy_id 
        AND tax.taxonomy = 'category' 
LEFT JOIN 
        wp_terms term
ON      term.term_id = tax.term_id
WHERE   wp_posts.post_type = 'post' 
        AND wp_posts.post_status = 'publish' 
        AND term.term_id is null

答案 2 :(得分:0)

UPDATE FROM `wp_posts` WHERE `post_category` SET `post_category` = '9' WHERE `post_category` = '';