get_post_status_object() WordPress Function

The get_post_status_object() function is used to retrieve a post status object by its name. This function is useful for plugin developers who need to programmatically change the post status of a post. For example, a plugin might need to change the post status from "pending" to "publish" when a certain action is taken. This function can also be used to programmatically check the status of a post. For example, a plugin might need to check if a post is "pending" before taking some action.

get_post_status_object( string $post_status ) #

Retrieve a post status object by name.


Description

Top ↑

See also


Top ↑

Parameters

$post_status

(string)(Required)The name of a registered post status.


Top ↑

Return

(stdClass|null) A post status object.


Top ↑

Source

File: wp-includes/post.php

function get_post_status_object( $post_status ) {
	global $wp_post_statuses;

	if ( empty( $wp_post_statuses[ $post_status ] ) ) {
		return null;
	}

	return $wp_post_statuses[ $post_status ];
}


Top ↑

Changelog

Changelog
VersionDescription
3.0.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
Show More