• in category There are too many post.
    Change category with SQL
    The post on the category I want to transfer to other categories.
    Example:
    A category post count:900.000
    B,C,D,E,F category post count:0
    I Want;
    A category post count:150.000
    B category post count:150.000
    C category post count:150.000
    D category post count:150.000
    E category post count:150.000
    F category post count:150.000
    how can I do?
    Sample website is missimoda.com and motocarstyle
    or new trend fashion

Viewing 3 replies - 1 through 3 (of 3 total)
  • sidHitesh7

    (@siddhapurahitesh)

    I suggest not use Direct SQL query to update/add category, rather use WordPress standard functions/classes. It’ll automatically manage all for running version of WordPress.

    Make new file at root of WordPress like change.php and put below code and change your category with code

    require('wp-load.php');
    $posts = new WP_Query( array('category_name'=>'Category 1') );
    if ( $posts->have_posts() ) : while ($posts->have_posts()) : $posts->the_post();
        wp_set_object_terms(get_the_ID(), 'Category 2', 'category');
    endwhile; endif;
    Thread Starter merper

    (@merper)

    code is work. category changes.
    But only 20 post setting working code, to website offline.
    20 post setting:settings ->reading->Blog pages show at most=20

    the server’s RAM capacity is insufficient (2gb ram)
    I can not run so code…

    sidHitesh7

    (@siddhapurahitesh)

    For all post you have to pass posts_per_page=-1 in WP_Query. See below code

    require('wp-load.php');
    $posts = new WP_Query( array('category_name'=>'Category 1',  'posts_per_page'=-1) );
    if ( $posts->have_posts() ) : while ($posts->have_posts()) : $posts->the_post();
        wp_set_object_terms(get_the_ID(), 'Category 2', 'category');
    endwhile; endif;
Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Change category with SQL’ is closed to new replies.