Post
Single post/page entity
Properties & methods
Property | Type | |
---|---|---|
ID | Post ID | int |
ancestor | Retrieves the root ancestor of a post | object |
ancestors(reverse) | Retrieves the ancestors of a post | array |
author | Post author as a User | object |
blocks | Parses blocks out of a content string. | array |
children(order) | Get post children | array |
class | Retrieves the class names for the post container element. | string |
classes | Retrieves the class names for the post container element. | array |
comment_count | Post comment total count | int |
comments | Perform a WP_Comment_Query | object |
comment_status | Post comment status | string |
content(index) | Post content, if post has blocks, return a parsed content as string, useful to create search index for instance | string |
custom_fields(name) | Get ACF value | mixed |
date(format) | Formatted post created date, see mysql2date | string |
date_gmt(format) | Formatted post created gmt date, see mysql2date | string |
excerpt | Post excerpt, if empty generate one from content | string |
link | Post url | string |
menu_order | Post menu order from Backend | int |
meta(name) | Get post meta | mixed |
modified(format) | Formatted post modified date, see mysql2date | string |
modified_gmt(format) | Formatted post modified gmt date, see mysql2date | string |
next(in_same_term , excluded_terms, tax) | Retrieves the next post that is adjacent to the current post, see get_next_post | object |
parameters | Get post url parameters based on rewrite rules | object |
parent | Post parent | object |
password | post password | string |
path | Relative post link without prefix | string |
prev | Retrieves the previous post that is adjacent to the current post, see get_previous_post | object |
siblings(order) | Retrieves all posts with the same post parent | array |
slug | Post slug | string |
state | Post state, based on 'page_on_*' option | string |
status | Post status | string |
taxonomies(public) | Returns the objects of the taxonomies which are registered for the post type | array |
template | Post template slug | string |
term(tax, args) | Primary term | object |
terms(tax, args, order, limit) | Perform a WP_Term_Query, return TermCollection | object |
thumbnail | Retrieves thumbnail | object |
title | Post title | string |
type(property) | Return post type, use property param to get specific post type object property | mixed |
has_block(name) | Check if post has a specific block ( Gutenberg ) | bool |
has_blocks | Check if post has blocks ( Gutenberg ) | bool |
has_children | Count post children | bool |
has_excerpt | Excerpt has been filled | bool |
has_parent | Post has parent | bool |
is_current | Post is currently viewed | bool |
is_public | Post is public | bool |
is_sticky | Post is sticky | bool |
meta | Get post meta value | mixed |
Dates are formatted using date_format
option, add false as parameter to return raw date : $post->getDate(false)
or {{ post.date(false) }}
Examples
Check for a specific block
Useful when a block needs a specific code in the layout Example: load recaptcha library if post contains the "contact-form" acf block
Display post meta
see https://developer.wordpress.org/reference/functions/get_post_meta/
Display ACF fields
Display a repeater fields with position and title sub-fields see https://www.advancedcustomfields.com/resources/get_field/
Display thumbnail
or using picture twig filter
Display blocks
Show comments : $args=['status'=>'approve', number=>5]
Show ancestors
Query term
Query terms : $criteria=[], array $orderBy = null, $limit = null, $offset = null
When using Yoast SEO, primary term will be the first item of the array
Last updated