the_post WordPress Action Hook

The the_post hook is one of the most important hooks in WordPress. It is called after the post content has been retrieved from the database and is used to setup the post data before it is displayed on the screen. This hook is used by many plugins and themes to setup their own data structures and display settings for the post.

do_action_ref_array( 'the_post', WP_Post $post, WP_Query $query ) #

Fires once the post data has been set up.


Parameters

$post

(WP_Post)The Post object (passed by reference).

$query

(WP_Query)The current Query object (passed by reference).


Top ↑

More Information

The ‘the_post’ action hook allows developers to modify the post object immediately after being queried and setup.

The post object is passed to this hook by reference so there is no need to return a value.

Top ↑

Example


function my_the_post_action( $post_object ) {
// modify post object here
}
add_action( 'the_post', 'my_the_post_action' );


Top ↑

Source

File: wp-includes/class-wp-query.php

View on Trac



Top ↑

Changelog

Changelog
VersionDescription
4.1.0Introduced $query parameter.
2.8.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.

Show More