WPSEO_Replace_Vars::get_terms()
Retrieve a post's terms, comma delimited.
Метод класса: WPSEO_Replace_Vars{}
Хуки из метода
Возвращает
Строку
. Either a single term or a comma delimited string of terms.
Использование
$WPSEO_Replace_Vars = new WPSEO_Replace_Vars(); $WPSEO_Replace_Vars->get_terms( $id, $taxonomy, $return_single );
- $id(int) (обязательный)
- ID of the post to get the terms for.
- $taxonomy(строка) (обязательный)
- The taxonomy to get the terms for this post from.
- $return_single(true|false)
- If true, return the first term.
По умолчанию: false
Код WPSEO_Replace_Vars::get_terms() WPSEO Replace Vars::get terms Yoast 24.9
public function get_terms( $id, $taxonomy, $return_single = false ) { $output = ''; // If we're on a specific tag, category or taxonomy page, use that. if ( ! empty( $this->args->term_id ) ) { $output = $this->args->name; } elseif ( ! empty( $id ) && ! empty( $taxonomy ) ) { $terms = get_the_terms( $id, $taxonomy ); if ( is_array( $terms ) && $terms !== [] ) { foreach ( $terms as $term ) { if ( $return_single ) { $output = $term->name; break; } else { $output .= $term->name . ', '; } } $output = rtrim( trim( $output ), ',' ); } } unset( $terms, $term ); /** * Allows filtering of the terms list used to replace %%category%%, %%tag%% * and %%ct_<custom-tax-name>%% variables. * * @param string $output Comma-delimited string containing the terms. * @param string $taxonomy The taxonomy of the terms. */ return apply_filters( 'wpseo_terms', $output, $taxonomy ); }