WP: Getting post fields of single – get_post_field()

get_post_field(string $field, int|WP_Post $post = null, string $context = ‘display’)

Official: https://developer.wordpress.org/reference/functions/get_post_field/

Parameters

$field string required
Post field name.

$post int|WP_Post optional
Post ID or post object. Defaults to global $post.
Default:null

$context string optional
How to filter the field. Accepts ‘raw’, ‘edit’, ‘db’, or ‘display’. Default ‘display’.
Default:’display’

Usage

e.g. Getting slug name.

get_post_field('post_name', get_the_ID());

You can get default post fields

ID
post_author
post_date
post_date_gmt
post_content
post_title
post_excerpt
post_status
comment_status
ping_status
post_password
post_name (slug)
to_ping
pinged
post_modified
post_modified_gmt
post_content_filtered
post_parent
guid
menu_order
post_type
post_mime_type
comment_count
filter

TagTimes

Simple time tracking tool
Developed by Namu Works