WPSEO_Replace_Vars::retrieve_cf_custom_field_name()
Retrieve a post/page/cpt's custom field value for use as replacement string.
Метод класса: WPSEO_Replace_Vars{}
Хуков нет.
Возвращает
Строку|null
.
Использование
// private - только в коде основоного (родительского) класса $result = $this->retrieve_cf_custom_field_name( $var_to_replace );
- $var_to_replace(строка) (обязательный)
- The complete variable to replace which includes the name of the custom field which value is to be retrieved.
Код WPSEO_Replace_Vars::retrieve_cf_custom_field_name() WPSEO Replace Vars::retrieve cf custom field name Yoast 24.9
private function retrieve_cf_custom_field_name( $var_to_replace ) { $replacement = null; if ( is_string( $var_to_replace ) && $var_to_replace !== '' ) { $field = substr( $var_to_replace, 3 ); if ( ! empty( $this->args->ID ) ) { // Post meta can be arrays and in this case we need to exclude them. $name = get_post_meta( $this->args->ID, $field, true ); if ( $name !== '' && ! is_array( $name ) ) { $replacement = $name; } } elseif ( ! empty( $this->args->term_id ) ) { $name = get_term_meta( $this->args->term_id, $field, true ); if ( $name !== '' ) { $replacement = $name; } } } return $replacement; }