You might want to look at the routine that WP uses for this: locate_template(). It is in wp-includes/theme.php and is called from a number of functions in that file. Those functions are used by wp-includes/template-loader.php to select the correct type of template based on the current page and then walk up the theme hierarchy looking for a match.
Related Posts:
- Get image URL from media library in input
- How to provide page_template path in custom plugin using WordPress
- Pass PHP variable to javascript
- Custom media upload content for inserting custom post shortcode
- Redesigning Custom Post Type “Add New” page
- How to Remove Certain Screen Options and Meta Boxes from add/edit post type?
- Is it possible to define a template for a custom post type within a plugin independent of the active theme?
- How to add custom content template part for a custom post type on main query using a plugin
- Page Templates from plugin not working after upgrading WP to 4.7 or upper version
- How can I add a custom header to a custom template in a plugin without using the theme folders
- How to load a new template page according to a particular URL?
- How to get the custom page get_permalink?
- Updating post meta for custom post types
- Template for custom post type shows all posts instead of just one
- Custom url structure for custom template
- remove custom taxonomy metabox form custom post type
- Custom Post Type Statuses
- How to Build a Movie Library in WordPress 3.x
- Way to hook into a sidebar call to replace it with a custom sidebar
- Override comments.php template with plugin
- Can we use a webservice with WordPress?
- Loco Translate: Custom Post and Custom Taxonomy Labels not translated in wp-admin menu
- WP Post Template – Templates in own folder
- Register Page Template from Plugin
- Is it possible to create Custom Post plug-in?
- Creating a custom post type, adding custom meta fields, preventing all future editability of posts of this type
- Making a Template for a CPT created by a plugin
- Plugin-generated pages use Not Found or Pages Archive templates?
- Perform internal redirect in WordPress?
- Unable to delete custom post types, confusion around capabilities
- Adding CSS to custom post type admin page causes error
- Redirect to another page using contact form 7? [closed]
- how to force tag page layout to use same as search layout?
- How can I use a file in my plugin as a replacement for single.php on custom-post-type query?
- Disable Individual Plugins (specifically in Custom Post Types) on a per-post basis?
- Using ACF default value to autoincrement a number field
- Default taxonomy template in plugin, override in theme
- How to Resize the Custom Post Images?
- Amazon.com intergration with WordPress?
- Adding custom meta boxes to specified custom post type
- How to use template inside plugin shortcode with variables for big HTML code
- Plugin generated unexpected output – No PHP errors
- How do I show content from a plugin using the template the site is currently working with?
- Custom Post Type template for homepage
- Custom Post Type, Custom Columns List
- Pass PHP variable to javascript
- Need to edit author permissions | custom taxonomy
- Is it possible to pin a post in second position from top
- How to get the custom field value using SQL query
- Check if theme supports sidebar
- How to display the category name in the tab and post inside the tab in WordPress?
- custom post type plugin error [closed]
- How to display the custom post related blog by category?
- Problem with checked box on wp car manager plugin
- Ultimate Members Default Post Layout problem
- custom post type get_posts() function not work
- Create multiple posts when a custom post is created
- $wpdb->insert not working inside save_post tag
- Cannot view Custom Post Type no matter what I try
- How to prevent redoing get_posts queries and make results available to other scripts?
- how to do Thematic like this website using wordpress?
- How to add jquery to my custom post type wp plugin
- show Visual form builder in the front end
- Synch Custom Post Types (and Custom Fields, Cats, etc.) Between WordPress Sites
- get_option include in my adsense
- Making a Custom Post Type Publish Loop
- Is an Office a custom post type [closed]
- WordPress show different custom post type
- Wrong block appender button showing
- How to make a Template page to show the information of different things Shop and Product page?
- How to access the page without registering in wordpress
- CPT template is not being automatically used single post pages
- How to make content as required in custom post type?
- public custom posts not showing in my wordpress plugin
- Remove H1 title in admin post edit screen
- How to Display News in a Timeline with Headline, Category, and Time?
- Load a custom post type template.html from a plugin
- Does a plugin’s “main” file need to be named the same as the folder containing it?
- use WordPress theme / plugin editor in my plugin
- WordPress hook for visiting a post
- Fatal error: Class not found in
- What user roles should have wp_unique_post_slug_is_bad_flat_slug filter applied?
- __callStatic method handler passed to add_action causes bug in PHP
- New databes tables with – WooCommerce – for developers [closed]
- WordPress error: Options page Setting_ not found in the allowed options list
- flush_rewrite_rules() not working with update_option_{$option}
- How to ignore extra whitespaces in translation functions like _e?
- Price comparison table based on Custom Post Type?
- The “Child Pages Shortcode” plugin, block template
- How to get a custom page through plugin?
- WP Forms not displaying,becomming an fatal error
- Undefined index: custom_post_template_present
- Using foreach loop for `$instance` of form and update array widget iteration
- wp meta_query meta_value compare =REGEXP delimited by space
- How to insert variable which contain array value in wp_options table?
- Array to string conversion error when trying to POST multidimensional array
- How to Overwrite validate_plugin function
- Form data to wordpress DB
- Register additional wp plugin directory
- Send email notification when meet the condition