WPSEO_Meta::get_value()
Get a custom post meta value.
Returns the default value if the meta value has not been set.
{@internal Unfortunately there isn't a filter available to hook into before returning the results for get_post_meta(), get_post_custom() and the likes. That would have been the preferred solution.}}
Метод класса: WPSEO_Meta{}
Хуков нет.
Возвращает
Строку
. All 'normal' values returned from get_post_meta() are strings. Objects and arrays are possible, but not used by this plugin and therefore discarted (except when the special 'serialized' field def value is set to true - only used by add-on plugins for now). Will return the default value if no value was found. Will return empty string if no default was found (not one of our keys) or if the post does not exist.
Использование
$result = WPSEO_Meta::get_value( $key, $postid );
- $key(строка) (обязательный)
- Internal key of the value to get (without prefix).
- $postid(int)
- Post ID of the post to get the value for.
Код WPSEO_Meta::get_value() WPSEO Meta::get value Yoast 24.9
public static function get_value( $key, $postid = 0 ) { global $post; $postid = absint( $postid ); if ( $postid === 0 ) { if ( ( isset( $post ) && is_object( $post ) ) && ( isset( $post->post_status ) && $post->post_status !== 'auto-draft' ) ) { $postid = $post->ID; } else { return ''; } } $custom = get_post_custom( $postid ); // Array of strings or empty array. $table_key = self::$meta_prefix . $key; // Populate the field_def using the field_index lookup array. $field_def = []; if ( isset( self::$fields_index[ $table_key ] ) ) { $field_def = self::$meta_fields[ self::$fields_index[ $table_key ]['subset'] ][ self::$fields_index[ $table_key ]['key'] ]; } // Check if we have a custom post meta entry. if ( isset( $custom[ $table_key ][0] ) ) { $unserialized = maybe_unserialize( $custom[ $table_key ][0] ); // Check if it is already unserialized. if ( $custom[ $table_key ][0] === $unserialized ) { return $custom[ $table_key ][0]; } // Check whether we need to unserialize it. if ( isset( $field_def['serialized'] ) && $field_def['serialized'] === true ) { // Ok, serialize value expected/allowed. return $unserialized; } } // Meta was either not found or found, but object/array while not allowed to be. if ( isset( self::$defaults[ self::$meta_prefix . $key ] ) ) { // Update the default value to the current post type. switch ( $key ) { case 'schema_page_type': case 'schema_article_type': return ''; } return self::$defaults[ self::$meta_prefix . $key ]; } /* * Shouldn't ever happen, means not one of our keys as there will always be a default available * for all our keys. */ return ''; }