Alert: This function’s access is marked private. This means it is not intended for use by plugin or theme developers, only in other core functions. It is listed here for completeness.

_resolve_template_for_new_post() WordPress Function

The resolve_template_for_new_post() function is used to resolve the template for a new post. This function is used by the WordPress core when a new post is created.

_resolve_template_for_new_post( WP_Query $wp_query ) #

Sets the current WP_Query to return auto-draft posts.


Description

The auto-draft status indicates a new post, so allow the the WP_Query instance to return an auto-draft post for template resolution when editing a new post.


Top ↑

Parameters

$wp_query

(WP_Query)(Required)Current WP_Query instance, passed by reference.


Top ↑

Source

File: wp-includes/block-template.php

function _resolve_template_for_new_post( $wp_query ) {
	remove_filter( 'pre_get_posts', '_resolve_template_for_new_post' );

	// Pages.
	$page_id = isset( $wp_query->query['page_id'] ) ? $wp_query->query['page_id'] : null;

	// Posts, including custom post types.
	$p = isset( $wp_query->query['p'] ) ? $wp_query->query['p'] : null;

	$post_id = $page_id ? $page_id : $p;
	$post    = get_post( $post_id );

	if (
		$post &&
		'auto-draft' === $post->post_status &&
		current_user_can( 'edit_post', $post->ID )
	) {
		$wp_query->set( 'post_status', 'auto-draft' );
	}
}


Top ↑

Changelog

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