I have the ID of a page,
I just need to grab the template situated with this page.
What function would do this for me?
I have the ID of a page,
I just need to grab the template situated with this page.
What function would do this for me?
It's a bit dated (2 years) but this reply may help you.
http://wordpress.org/support/topic/get-name-of-page-template-on-a-page?replies=14#post-1175685
I've tried
global $wp_query;
$template_name = get_post_meta( $wp_query->post->ID, '_wp_page_template', true );
$template_name holds the current page template, whereas I want to use another pages' ID.
So I've tried $post->ID (I can access this, it returns integer).
$template_name = get_post_meta( $post->ID, '_wp_page_template', true );
but $template_name returns an empty string.
global $wpdb;
$query = 'SELECT meta_value FROM '.$wpdb->prefix.'postmeta WHERE meta_key = '_wp_page_template' AND post_id = '.$post->ID;
$template_name = $wpdb->get_var($wpdb->prepare($query));
Give that a shot. It's off the cuff so you may have to tweak it.
You must log in to post.