get_post_field()
Проверено на WordPress 6.9, обновлено Источник: WordPress Developer Resources.
Сигнатура
get_post_field( string $field, int|WP_Post $post = null, string $context = 'display' ): int|string|int[]
Описание
Примеры поля записи: ‘post_type’, ‘post_status’, ‘post_content’ и т. д.; они основаны на именах свойств или ключей объекта записи.
Значения контекста основаны на функциях фильтрации таксономий, а поддерживаемые значения определяются внутри этих функций.
См. alsosanitize_post_field()
Оригинал (английский)
Examples of the post field will be, ‘post_type’, ‘post_status’, ‘post_content’, etc and based off of the post object property or key names.
The context values are based off of the taxonomy filter functions and supported values are found within those functions.
Параметры
$field
string
обязательный
$post
int|WP_Post
необязательный
= null
$context
string
необязательный
= 'display'
Возвращаемое значение
int|string|int[]
Исходный код
wp-includes/post.php:1206
function get_post_field( $field, $post = null, $context = 'display' ) {
$post = get_post( $post );
if ( ! $post ) {
return '';
}
if ( ! isset( $post->$field ) ) {
return '';
}
return sanitize_post_field( $field, $post->$field, $post->ID, $context );
}
История изменений
| Версия | Описание |
|---|---|
| 4.5.0 | The $post parameter was made optional. |
| 2.3.0 | Introduced. |

