It looks like nothing was found at this location. Maybe try searching?
add_action('save_post', function ($post_id) { // Stop autosaves and revisions if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) return; if (wp_is_post_revision($post_id)) return; // Only apply to standard posts if (get_post_type($post_id) !== 'post') return; $terms = wp_get_post_terms($post_id, 'category'); // If zero or one category, nothing to enforce if (count($terms) <= 1) return; // Prefer deepest category (child beats parent) usort($terms, function ($a, $b) { return $b->parent - $a->parent; }); // Keep only one category wp_set_post_terms( $post_id, array($terms[0]->term_id), 'category', false ); }, 20);
It looks like nothing was found at this location. Maybe try searching?