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?
- Custom single template for a specific category
- How to insert a logo in the header?
- How to move page template files like page-{slug}.php to a sub-directory?
- Is it possible to stop selected plugins from loading on certain template pages?
- Form Submitting Error with get_template_part()
- Page template in two level deep folder
- Create “File-less” Page Template in Functions.php
- What is the right way to include a wp-admin file in your theme?
- 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
- How does WordPress decide what template to use as frontpage
- How can I get wp_head() as a string instead of echoing it?
- Why does my short code get executed before other content?
- Hide certain pages / posts on wp-admin, show custom filter
- How can I see what template parts are being called for rendering the viewable page?
- Where is default wp_head() implemented?
- 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 Handle CSS for Multiple Header header.php Files?
- How to load different CSS in different Header?
- Static Front Page problem
- Accessing $post variable from template part
- Pagination & get_pages?
- Can not Remove Archives and Meta from Sidebar
- Page attribute template dropdown not displayed even the syntax is correct
- How to override BuddyPress 3.0 bp-nouveau theme files?
- Enqueued Stylesheets Effecting Admin Styles
- Adding variable to get_template_part
- Setting hero/splash section as a blog post
- How to regenerate thumbnails when they’re stored on S3
- Where is the correct place(s) in twentysixteen’s header.php to add a Google webfont?
- How to retrieve an image from a post and display it before excerpt of a post? [duplicate]
- Do I really need the div class entry?
- Any tag pagination page (except the 1st page) loads index.php template instead of tag.php
- Switching between custom templates in a post type of the admin menu
- How do I update WooCommerce template files in my theme? [closed]
- Sub folder CSS that’s read by Admin panel
- Page template across themes
- wordpress custom theme import and export options for sample data [closed]
- New template, where to place CSS?
- how do you create an admin interface in plugin for your theme
- Warning/Error in Admin Panel while developing theme
- Check if password protected post is visible
- get_query_var() and permalinks
- What is the best way to handle multiple calls to get_template_directory_uri() and similar functions?
- Toggle Sidebar Display
- Why is the Links Manager visible?
- Add theme templates for child categories into the template hierarchy
- Move theme templates to subfolder without losing page associations
- Theme development question regarding layouts
- Why are theme templates organized as multiple point of entry PHP files instead of reusing your theme’s index.php?
- WordPress page templates in a directory
- WordPress Theme Development: How to redirect templates the right way?
- How do I create a custom partial / template?
- 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
- get_page_template returning nothing
- Load child template based on parent
- 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?
- Override template file i subfolders
- Can Page Templates be Applied to Archive and Post Templates?
- Custom metabox for custom page template
- 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 to create a custom template to admin dashboard
- Do i need to keep all the default WP templates files in a theme?
- How to add a button which saves the post then executes a function
- How can I detect hierarchal relationships beyond children (grandchild, great-grandchild, etc)?
- how to display search term in the template full site editor
- How to create a custom page(not a template) in a theme
- Sort wp_query by sum of two meta fields
- How to override p2 breathe theme plugin in content template file?
- Template selection area is not visible on page editor sidebar in wordpress twentty sixteen default theme