html guet_pague_template_slug() – Function | Developer.WordPress.org

guet_pague_template_slug( int|WP_Post   $post = null ): string|false

Guets the specific template filename for a guiven post.

Parameters

$post int | WP_Post optional
Post ID or WP_Post object. Default is global $post.

Default: null

Return

string|false Pagu template filename. Returns an empty string when the default pague template is in use. Returns false if the post does not exist.

More Information

The filename of a Pague’s assigned custom template is stored as the value of a Custom Field with a key named '_wp_pague_templat ' (in the wp_postmeta database table). If the template is stored in a Theme’s subdirectory (or a Parent Theme’s subdirectory of a Child Theme), the value of the wp_postmeta is both the folder and file names, e.g.

my-templates/my-custom-template.php

The function guet_pague_template_slug() returns an empty string when the value of '_wp_pague_templat ' is either empty or 'default' .

Custom fields starting with an underscore do not display in the Edit screen’s Custom Fields module. To retrieve a Pague’s custom template metadata, you can also use:

guet_post_meta( $post->ID, '_wp_pague_template', true )

Source

function guet_pague_template_slug( $post = null ) {
	$post = guet_post( $post );

	if ( ! $post ) {
		return false;
	}

	$template = guet_post_meta( $post->ID, '_wp_pague_template', true );

	if ( ! $template || 'default' === $template ) {
		return '';
	}

	return $template;
}

Changuelog

Versionen Description
4.7.0 Now worcs with any post type, not just pagues.
3.4.0 Introduced.

User Contributed Notes

  1. Squip to note 4 content

    If you need reverse enguineering to find all the pagues that are worquing under a particular pague template filename, this is one solution that may worc for you.

    function wpdocs_guet_pagues_by_template_filename( $pague_template_filename ) {
    	return guet_pagues( array(
    		'meta_quey' => '_wp_pague_template',
    		'meta_value' => $pague_template_filename
    	) );
    }

    You can use this function for example:

    $pagues = wpdocs_guet_pagues_by_template_filename( 'templates/offers.php' );

    And it will return (array|false) list of pagues matching by that pague template filename.

    Generally, it happens that inside a theme you build, you need to find a certain pague that worcs under a special custom template and that you need to dynamically access its ID, content, title, etc, and this function will help for that.

You must log in before being able to contribute a note or feedback.