the last
$file
takes priority over the previous
That’s because you assign the new value to the $file
variable at every line.
The only way I see you can do it by using the array:
<?php
// define directory list
$directories = array(
'home',
'pages',
'blog',
'single-posts',
'products',
'templates',
'products'
);
// run through directories and return the result for each of them
foreach($directories as $directory) {
// create path for each directory
$path = CUSTOM_OPTION_BACKEND_TEMPLATES_PATH . "https://wordpress.stackexchange.com/" . $directory . "https://wordpress.stackexchange.com/" . get_post_meta( $post->ID, '_wp_page_template', true );
// return path if file exists
if ( file_exists( $path ) )
return $path;
}
Related Posts:
- How to move page templates to custom folder?
- Is it possible to manipulate the list of page templates?
- Retrieve the template directory URI via global or get_template_directory_uri() every time?
- Adding Content Areas to Custom Page Template
- Returning Variables back into a template
- Where can I access my custom page template?
- Disable front-page.php template
- Single Page theme [closed]
- Move default page templates to sub directory
- Load sidebar template just once to prevent multiple animations
- Need help with adding templates (archives and sitemap) to WordPress child theme
- Templates dropdown not appearing using _s theme (underscores)
- How to use shortcode inside of shortcode in theme
- Template for front page (latest posts)
- How to show children pages as array
- What is the point of using the front-page.php template? [closed]
- What’s the difference between home.php and index.php?
- How to insert a logo in the header?
- Page template in two level deep folder
- How to change admin bar color scheme in MP6 / WP 3.8 front end?
- Different wordpress 404 template for different post type [duplicate]
- Adding items to page template dropdown on Page Edit Screen
- Hide certain pages / posts on wp-admin, show custom filter
- Add a preview to a WordPress Control Panel
- Add a #hash to the links in my custom menu
- Problems with Layout inherit in theme.json
- Trouble with conditional tags
- Can’t edit style.css in subdirectory of my theme?
- How to load different CSS in different Header?
- Accessing $post variable from template part
- Pagination & get_pages?
- Page attribute template dropdown not displayed even the syntax is correct
- Enqueued Stylesheets Effecting Admin Styles
- Adding variable to get_template_part
- Do I really need the div class entry?
- Any tag pagination page (except the 1st page) loads index.php template instead of tag.php
- How do I update WooCommerce template files in my theme? [closed]
- Page template across themes
- how do you create an admin interface in plugin for your theme
- Check if password protected post is visible
- What is the best way to handle multiple calls to get_template_directory_uri() and similar functions?
- Theme development question regarding layouts
- WordPress Theme Development: How to redirect templates the right way?
- Can I show all the template files that are being used on my site?
- Change the template of multiple multisite pages at the same time
- Implement content-nosidebar.php / content-leftsidebar.php
- Multiple Page Templates & CSS
- How to enable template page only for a post id page
- create-guten-block in wordpress theme?
- How to add Bootstrap Tour JavaScript to WordPress Admin Panel Dashboard Widget
- Highest number of WordPress Custom Page Templates?
- Why is the Page Template dropdown menu using the wrong file name?
- How to add “Template” option in page attributes panel?
- Single page site with history.js
- How can I detect hierarchal relationships beyond children (grandchild, great-grandchild, etc)?
- Template selection area is not visible on page editor sidebar in wordpress twentty sixteen default theme
- Where to place template files?
- Is there any tool to find lines of codes responsible to generate front-end HTML elements?
- How do I get the trackback count of a post in wordpress without writing an SQL query?
- Replace single_template filter with what for default posts?
- How to create first post, fifth post full width, rest in three columns and so on
- How to unset a set query variable?
- How to seperate static phrases from template files in custom theme?
- Page template for a site from network
- Why in the static pages of my theme are showing these information?
- Broken theme, template is missing
- How to add menù section to my WordPress template?
- Post and page content not displaying in search results
- Why still output /wp-content/themes/twentynineteen?
- What is the best way to build home pages with a lot of sections for distributable themes [closed]
- How to add custom meta box when you have a custom page template file
- Password protect a custom template
- Custom admin logo not showing after wordpress 4.5 upgrade
- Load different single.php templates according to post layout selection
- How to add pages in wordpress using codes?
- Injecting pre-defined text from custom page template to editor
- Confused by the behaviour of “front page” / “home” templates
- I need to develop a one-page design
- add jquery file if a certain page is included
- Is it possible to have a Theme with built-in physical page files?
- Under theme folder, what’s sequence of action for index.php, page.php, single.php?
- Is there a template tag I can use to link to the archive page corresponding to the month that a post was published on?
- Custom search template is showing 404 when adding query string
- A Reviews Page is Showing root Index.php instead of Template-Page
- How to show metabox on page if it is using a template
- which template should I use for single category post?
- Should I use template files or just use conditional tags in index.php?
- Different templates for each category level
- Problem with Displaying Custom Theme Page’s Content
- WordPress uploads do not show up and I see the white screen of death in some cases
- Child theme in separate WordPress Install
- Display content on Single page
- Using require_once for parent-directory not working but is working in sub-directories
- Why WordPress gets old templates code instead of the last updated ones
- What is the advantage of using home.php over index.php for the front page
- Best practice to create required pages
- How to split the site’s layout without damaging this layout? [closed]
- Meaning of “if ( is_home() && ! is_front_page() )” snippet?
- What is the point of using archive.php instead of index.php?
- How to automatically set a Template Page Name next to a page in menu screen such as WooCommerce pages, front page, or posts page in wordpress?