So I’m doing a query like this:

$the_query = new WP_Query( array( ‘meta_key’ => ‘homepage’, ‘meta_value’ => ‘yes’,
‘post_type’ => ‘page’, ‘orderby’ => ‘modified’, ‘posts_per_page’ => 1 ) );

To get a single page with a specific key value, how do I get the page template from a query like this, if it has one?

Answer

This should do the trick for you. This shows what template file is stored in post_meta, if one has been selected in the admin panel:

If you want to see if the page is the homepage, use is_home() or is_front_page().

If you want to see what template files are generating the page, use this in your functions.php:

Tagged with →  
Share →

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>