Get page by template?

The page template’s filename is stored as a post meta with key ‘_wp_page_template’, so basically you can use get_post_meta($post_id, '_wp_page_template', true); to get the template filename for the page with ID $post_id.

You can also do the reverse (i.e. getting id from page template filename) using Custom Field Parameters in WP_Query or other wordpress functions.

Also there is a conditional function is_page_template which checks if the current page’s template is the one specified in parameter

These will probably solve your problem & maybe help to get rid of the hardcoded stuff.

Leave a Comment