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.
Related Posts:
- Searching multiple custom post types and pages
- Taxonomy, Terms, and Template Files
- How to pass URL parameters for advanced taxonomy queries with multiple terms for one custom taxonomy
- Templates for Custom Post Types and Custom Taxonomies
- Custom taxonomy query for a custom post type
- TV Show database – Best way for structuring it?
- Need some templating advice for templating with custom post types and taxonomies
- Custom Post Type with Nested Taxonomy and Template Files
- Custom Post Type Archive Template
- custom post type archive template per custom taxonomy term
- custom taxonomy – Template not working
- Include different loop templates in search query
- Create separate template for shared custom taxonomy with shared terms
- Trying to manage templates on a blog with lots of custom taxonomies
- How do I provide a “show all posts” link in a paginated term archive?
- Multiple portfolios with one custom post type?
- Is it possible to use pages to apply static content to each taxonomy level?
- Making pages also serve as taxonomies? Or give full pages to taxonomies?
- Trying to edit the single page from a Custom Post
- Custom Post Type Taxonomies -Posts not showing in Category or Tag pages
- Should I use custom taxonomy or custom post type
- Query with no terms uses index.php template instead of archive.php
- Create template for taxonomy results limited by Custom Post Type
- Template for custom post with custom taxonomy
- Custom taxonomy and custom post type – wrong permalinks and template
- WordPress Doesn’t Generate Taxonomy Archive
- Custom taxonomy returns 404
- Template for all categories of a custom post type?
- Migrating a taxonomy’s tags to the native category
- Top Level pages in wordpress giving 404, but child pages working fine
- WordPress custom taxonomy template not working
- How can I get this request to use the Custom Post Type page template instead?
- Archive for a Taxonomy of a Custom Post type
- Template files for Custom Post Type and Taxonomy
- Main query not querying any posts in custom taxonomy template
- Loop through custom posts by taxonomy and display the titles in a list, it is repeating 8 times
- Which file/template is in charge of taxonomies for custom post types?
- How to get_term_meta on single custom post?
- Get template part with CPT and Custom Taxonomy conditionals
- How to create a template to show child terms of a MAIN taxonomy
- How to change single custom post template by custom taxonomy?
- Setting a homepage – doesn’t seem to work
- Create a custom taxonomy template that loops through child categories in term order?
- Tag template not returning posts [closed]
- How do I disable the built-in editor and automatically configure the properties of new pages?
- Post template with breadcrumb needs to show page navigated from
- Add custom template ‘sub-page’ to Custom Post type?
- Custom Post Taxonomy Template Not Loading Properly
- Show posts from custom post type sorted by category/taxonomy on a one-pager/page
- taxonomy – templates are not loading
- Custom taxonomy with custom post type template not showing
- Custom taxonomy template for custom fields loop [closed]
- Templates for CPT not working
- Single taxonomy for different custom post types
- How should i name the .php file to show custom posts under a taxonomy’s term?
- I want to create an archive and single page for a custom taxonomy for a custom post type
- Custom Post Type tag taxonomy “Page Not Found”
- template structure for CPT not clear
- WordPress Custom taxonomy template
- How to display custom post types AND regular posts separately on a shared taxonomy archive?
- Querying multiple taxonomies in URL leads to wrong taxonomy archive
- How to Associate Posts with Pages
- query_post while (have post) get_template_part()?
- Using custom post types within a section of a template
- Listing all custom post types using a specific term on the said term’s template page, in groups
- Most appropriate way to display CPT’s by children terms of custom taxonomies while retaining desired permalink structure?
- How to make a single Menu Item call another Mega Menu for Custom Post Types and Custom Taxonomies?
- Highlight specific menu item when custom post is page
- Only One Post of Custom Post Type Appearing on Template Page
- Custom Post Types using wrong template (index) instead of archive-{type}.php – previously worked as expected
- An script/Plugin for automatic page creation per term
- Custom Post type in separate database table for syncing
- Best Way to Leverage Custom Post Type Related Content and Consider SEO
- Dynamically Create Terms in Taxonomy when Custom Post Type is Published. Almost There!
- pre get posts changing the query
- Querying CPT with Two Taxonomies
- Get Custom Field Values by Another Custom Field in WordPress
- Wp Rest API request posts from a custom taxonomy
- How is this CPT code in functions.php adding a hidden “products” category?
- Displaying Multiple Post types in Taxonomy
- Display Recently Added Custom Post Types with Custom Taxonomy Shortcode
- How do I display tags for a custom post type single page?
- Dynamic dropdown select values depending on other custom field value
- Query Custom Post Type Taxonomy term with multiple parameters
- Permalink structure with custom taxonomies and custom post type like /parent-tax/child-tax/custom-post-type-name (with no base name)
- Querying Custom Post Type, ordering by Custom Taxonomy Pagination Not Working
- Rewrite custom post type with taxonomy
- how to count the current posts terms
- Add custom post type taxonomy tag to article class
- Custom Taxonomy dont save in a frontend form for post a custom post
- Get the taxonomy value in the post loop inside the archive page
- How to display custom post type taxonomy in Contact Form 7 text field
- Custom Post Type & Taxonomies – Rewrite
- Do not show child pages within a file page
- Change CPT permalink to use the category
- Custom post types & Pages hierarchy – Error 404
- Previous/Next custom post links within custom taxonomy
- Override “Parent” input for custom taxonomy
- Why is this custom post type defaulting to archive.php?
- Sorting custom post types by taxonomy (So close)