Add category to all post by using sql query?

You can run WordPress query to associate category to all posts.
Here is the code. What this code will do is check if a post is already in category id 67, if it’s not then it will assign category id to it.

<?php
    $args = array( 'posts_per_page' => -1, 'orderby' => 'post_date' );
    $posts = get_posts( $args );
    foreach ( $posts as $post ) :
        setup_postdata( $post );
        $category_id = 67;
        if ( !(in_category( $category_id )) ) {
            wp_set_object_terms( get_the_ID(), array( $category_id ), 'category', false );
        }
    endforeach;
?>

Paste this code in header or footer and load your website in browser. Check category id’s in admin section if all has been changed. If not then load website in browser again.

Don’t forget to remove this code once done.

tech