Yoast\WP\SEO\AI\Content_Planner\Infrastructure
WordPress_Category_Repository::find_by_name
Finds a category by name, returning the empty-category sentinel when no term matches.
The empty-category sentinel is a Category with name "" and id -1. It signals "no category" to the frontend so it can hide the category UI and skip applying any category to the post.
Метод класса: WordPress_Category_Repository{}
Хуков нет.
Возвращает
Category. The resolved category, or the empty-category sentinel when no term matches.
Использование
$WordPress_Category_Repository = new WordPress_Category_Repository(); $WordPress_Category_Repository->find_by_name( $name ): Category;
- $name(строка) (обязательный)
- The category name.
Код WordPress_Category_Repository::find_by_name() WordPress Category Repository::find by name Yoast 28.7
public function find_by_name( string $name ): Category {
$term = \get_term_by( 'name', $name, 'category' );
if ( $term instanceof WP_Term ) {
return new Category( $term->name, $term->term_id );
}
return new Category( '', -1 );
}