After the advice from every awesome person who helped, I finally got it to work. I just had to define $the_content instead of trying to use the hook get_the_content() alone. Now it’s tagging everything perfectly. Here is the final code for anyone who wants to use it in the future. Or you can just download my plugin when I’m finished making it. It will be free.
<?php
/**
* Plugin Name: Auto Post Tagger
* Plugin URI: http://www.sitecrafters.pro/plugins/auto-tagger.zip
* Description: The very 13th plugin that I have ever created.
* Version: 1.15
* Author: Cody King
* Author URI: http://sitecrafters.pro
*/
/**
* @snippet Auto Post Tagger
* @author Cody King
* @compatible WordPress 6.4.3
*/
function autotag( $post_id ) {
$keywords = ['Los Angeles','New York','Chicago','Houston','Phoenix'];
$the_content = apply_filters('the_content', get_the_content());
foreach ( $keywords as $keyword )
{
$keycheck = strpos( $the_content, $keyword );
if( $keycheck !== false )
{
$keyword = str_replace( ' ' , '-' , $keyword ); // Convert spaces to dashes "-"
wp_set_post_tags( $post_id , $keyword , true ); // Set tags to Post
}
}
}
add_action( 'save_post', 'autotag' );