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
- Loop custom taxonomy to get lists of cutom post types?
- Custom post type structure for posts with multiple child posts
- Get custom taxonomies from multiple posts
- Hierarchical Custom Post Types in Array
- Making certain categories of CPT not publicly queryable
- Pagination for Custom Taxonomy Page [duplicate]
- How can I make a custom post type sticky?
- Missing Posts in Custom Taxonomy List
- Custom Post Type permalink shows wrong page: homepage/index.php
- Search / Filter posts on Title/Content OR Tags
- using $wpdb to get custom post type with term
- Custom Post Type Taxonomy Filters
- Custom Taxonomy Doesn’t Show Up
- Categories sorting
- Mapping Subdomains in WordPress to give the appearance of a localised site, best approach?
- WP_Query most viewed posts, in multiple Post Types, last 30 days, excluding a specific taxonomy term
- Show posts from two or more custom taxonomy terms
- Customize my custom taxonomy table in Admin panel
- Allow user to set custom order to a list of custom taxonomies?
- get_category_parents for custom post type taxonomy
- Custom-Posttype & Custom Taxonomy WP_Query
- Custom loop with multiple taxonomy queries
- How to use custom taxonomies to reference complex relationships?
- Disable block with taxonomies at post page
- Return one unique custom post type result when it shares a custom taxonomy in WP_QUERY?
- Displaying custom taxonomy in the admin list of a custom post type
- Get parse_query filter to return slug instead of id
- Tax query not producing any results
- Custom post type and taxonomy – show related posts