generate_postdata() WordPress Function

The generate_postdata() function is used to generate an array of data for a new post. This array can then be used with the wp_insert_post() function to create a new post.

generate_postdata( WP_Post|object|int $post ) #

Generates post data.


Parameters

$post

(WP_Post|object|int)(Required)WP_Post instance or Post ID/object.


Top ↑

Return

(array|false) Elements of post, or false on failure.


Top ↑

Source

File: wp-includes/query.php

function generate_postdata( $post ) {
	global $wp_query;

	if ( ! empty( $wp_query ) && $wp_query instanceof WP_Query ) {
		return $wp_query->generate_postdata( $post );
	}

	return false;
}


Top ↑

Changelog

Changelog
VersionDescription
5.2.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.