How to automatically apply a category based on the post title?

You could try this. I havn’t really tested it, so I’m not sure it works – might require some small tweaks aswell.

function add_category_based_on_title( $post_id ) {

    // title
    $title = get_the_title( $post_id );

    // get first part of title
    $substr = explode( " ", $title )[0];

    // get category id
    $category_id = get_cat_ID( $substr ); 

    // check category
    if ( ! empty( $category_id ) ) ) {

        // set category
        wp_set_post_categories( $post_id, [ $category_id ], true )

    }

}
add_action( 'save_post', 'add_category_based_on_title' );

References:

https://codex.wordpress.org/Function_Reference/wp_set_post_categories
https://codex.wordpress.org/Function_Reference/get_cat_ID
https://developer.wordpress.org/reference/functions/get_the_title/

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)