Skip to main content
deleted 6 characters in body; edited title
Source Link
Pieter Goosen
  • 55.4k
  • 23
  • 115
  • 209

How to make $file = Create a variable with string, array or multiple values?

I'm running some functions that will allow a user to register their own custom templates to my custom theme from an external directory. They can see these page templates in the wp-adminwp-admin and they render on the frontend. 

Everything works fine with this, but I would like to register files from multiple directories, not just one directory.

I need to make $file$file equal multiple directories. I've tried an arrayarray. I've tried &&&& and a couple other things, including the below code, but nothing works. 

I'm not a pro, but what am I missing here? Can this be done? In the code below I see that the last $file =$file = takes priority over the previous $file =$file =.

So is there a way I can make $file$file equals multiple paths?

In short, I want $file$file to consider multiple paths.

The code probably explains itself what I am trying to achieve.

    $file = CUSTOM_OPTION_BACKEND_TEMPLATES_PATH .      '/home/'            . get_post_meta( $post->ID, '_wp_page_template', true );
    $file = CUSTOM_OPTION_BACKEND_TEMPLATES_PATH .      '/pages/'           . get_post_meta( $post->ID, '_wp_page_template', true );
    $file = CUSTOM_OPTION_BACKEND_TEMPLATES_PATH .      '/blog/'            . get_post_meta( $post->ID, '_wp_page_template', true );
    $file = CUSTOM_OPTION_BACKEND_TEMPLATES_PATH .      '/single-posts/'    . get_post_meta( $post->ID, '_wp_page_template', true );
    $file = CUSTOM_OPTION_BACKEND_TEMPLATES_PATH .      '/products/'        . get_post_meta( $post->ID, '_wp_page_template', true );
    $file = CUSTOM_OPTION_BACKEND_TEMPLATES_PATH .      '/templates/'       . get_post_meta( $post->ID, '_wp_page_template', true );
    $file = CUSTOM_OPTION_BACKEND_TEMPLATES_PATH .      '/products/'        . get_post_meta( $post->ID, '_wp_page_template', true );


if ( file_exists( $file ) ) {
    return $file;
} 

How to make $file = string, array or multiple values?

I'm running some functions that will allow a user to register their own custom templates to my custom theme from an external directory. They can see these page templates in the wp-admin and they render on the frontend. Everything works fine with this, but I would like to register files from multiple directories, not just one directory.

I need to make $file equal multiple directories. I've tried an array. I've tried && and a couple other things, including the below code, but nothing works. I'm not a pro, but what am I missing here? Can this be done? In the code below I see that the last $file = takes priority over the previous $file =.

So is there a way I can make $file equals multiple paths?

In short, I want $file to consider multiple paths.

The code probably explains itself what I am trying to achieve.

    $file = CUSTOM_OPTION_BACKEND_TEMPLATES_PATH .      '/home/'            . get_post_meta( $post->ID, '_wp_page_template', true );
    $file = CUSTOM_OPTION_BACKEND_TEMPLATES_PATH .      '/pages/'           . get_post_meta( $post->ID, '_wp_page_template', true );
    $file = CUSTOM_OPTION_BACKEND_TEMPLATES_PATH .      '/blog/'            . get_post_meta( $post->ID, '_wp_page_template', true );
    $file = CUSTOM_OPTION_BACKEND_TEMPLATES_PATH .      '/single-posts/'    . get_post_meta( $post->ID, '_wp_page_template', true );
    $file = CUSTOM_OPTION_BACKEND_TEMPLATES_PATH .      '/products/'        . get_post_meta( $post->ID, '_wp_page_template', true );
    $file = CUSTOM_OPTION_BACKEND_TEMPLATES_PATH .      '/templates/'       . get_post_meta( $post->ID, '_wp_page_template', true );
    $file = CUSTOM_OPTION_BACKEND_TEMPLATES_PATH .      '/products/'        . get_post_meta( $post->ID, '_wp_page_template', true );


if ( file_exists( $file ) ) {
    return $file;
} 

Create a variable with string, array or multiple values

I'm running some functions that will allow a user to register their own custom templates to my custom theme from an external directory. They can see these page templates in the wp-admin and they render on the frontend. 

Everything works fine with this, but I would like to register files from multiple directories, not just one directory.

I need to make $file equal multiple directories. I've tried an array. I've tried && and a couple other things, including the below code, but nothing works. 

I'm not a pro, but what am I missing here? Can this be done? In the code below I see that the last $file = takes priority over the previous $file =.

So is there a way I can make $file equals multiple paths?

In short, I want $file to consider multiple paths.

The code probably explains itself what I am trying to achieve.

    $file = CUSTOM_OPTION_BACKEND_TEMPLATES_PATH .      '/home/'            . get_post_meta( $post->ID, '_wp_page_template', true );
    $file = CUSTOM_OPTION_BACKEND_TEMPLATES_PATH .      '/pages/'           . get_post_meta( $post->ID, '_wp_page_template', true );
    $file = CUSTOM_OPTION_BACKEND_TEMPLATES_PATH .      '/blog/'            . get_post_meta( $post->ID, '_wp_page_template', true );
    $file = CUSTOM_OPTION_BACKEND_TEMPLATES_PATH .      '/single-posts/'    . get_post_meta( $post->ID, '_wp_page_template', true );
    $file = CUSTOM_OPTION_BACKEND_TEMPLATES_PATH .      '/products/'        . get_post_meta( $post->ID, '_wp_page_template', true );
    $file = CUSTOM_OPTION_BACKEND_TEMPLATES_PATH .      '/templates/'       . get_post_meta( $post->ID, '_wp_page_template', true );
    $file = CUSTOM_OPTION_BACKEND_TEMPLATES_PATH .      '/products/'        . get_post_meta( $post->ID, '_wp_page_template', true );


if ( file_exists( $file ) ) {
    return $file;
} 
added more relevant tags
Source Link

I'm running some functions that will allow a user to register their own custom templates to my custom theme from an external directory. They can see these page templates in the wp-admin and they render on the frontend. Everything works fine with this, but I would like to register files from multiple directories, not just one directory.

I need to make $file equal multiple directories. I've tried an array. I've tried && and a couple other things, including the below code, but nothing works. I'm not a pro, but what am I missing here? Can this be done? In the code below I see that the last $file = takes priority over the previous $file =.

So is there a way I can make $file equals multiple paths?

In short, I want $file to consider multiple paths.

The code probably explains itself what I am trying to achieve.

    $file = CUSTOM_OPTION_BACKEND_TEMPLATES_PATH .      '/home/'            . get_post_meta( $post->ID, '_wp_page_template', true );
    $file = CUSTOM_OPTION_BACKEND_TEMPLATES_PATH .      '/pages/'           . get_post_meta( $post->ID, '_wp_page_template', true );
    $file = CUSTOM_OPTION_BACKEND_TEMPLATES_PATH .      '/blog/'            . get_post_meta( $post->ID, '_wp_page_template', true );
    $file = CUSTOM_OPTION_BACKEND_TEMPLATES_PATH .      '/single-posts/'    . get_post_meta( $post->ID, '_wp_page_template', true );
    $file = CUSTOM_OPTION_BACKEND_TEMPLATES_PATH .      '/products/'        . get_post_meta( $post->ID, '_wp_page_template', true );
    $file = CUSTOM_OPTION_BACKEND_TEMPLATES_PATH .      '/templates/'       . get_post_meta( $post->ID, '_wp_page_template', true );
    $file = CUSTOM_OPTION_BACKEND_TEMPLATES_PATH .      '/products/'        . get_post_meta( $post->ID, '_wp_page_template', true );


if ( file_exists( $file ) ) {
    return $file;
} 

I need to make $file equal multiple directories. I've tried an array. I've tried && and a couple other things, including the below code, but nothing works. I'm not a pro, but what am I missing here? Can this be done? In the code below I see that the last $file = takes priority over the previous $file =.

So is there a way I can make $file equals multiple paths?

In short, I want $file to consider multiple paths.

The code probably explains itself what I am trying to achieve.

    $file = CUSTOM_OPTION_BACKEND_TEMPLATES_PATH .      '/home/'            . get_post_meta( $post->ID, '_wp_page_template', true );
    $file = CUSTOM_OPTION_BACKEND_TEMPLATES_PATH .      '/pages/'           . get_post_meta( $post->ID, '_wp_page_template', true );
    $file = CUSTOM_OPTION_BACKEND_TEMPLATES_PATH .      '/blog/'            . get_post_meta( $post->ID, '_wp_page_template', true );
    $file = CUSTOM_OPTION_BACKEND_TEMPLATES_PATH .      '/single-posts/'    . get_post_meta( $post->ID, '_wp_page_template', true );
    $file = CUSTOM_OPTION_BACKEND_TEMPLATES_PATH .      '/products/'        . get_post_meta( $post->ID, '_wp_page_template', true );
    $file = CUSTOM_OPTION_BACKEND_TEMPLATES_PATH .      '/templates/'       . get_post_meta( $post->ID, '_wp_page_template', true );
    $file = CUSTOM_OPTION_BACKEND_TEMPLATES_PATH .      '/products/'        . get_post_meta( $post->ID, '_wp_page_template', true );


if ( file_exists( $file ) ) {
    return $file;
} 

I'm running some functions that will allow a user to register their own custom templates to my custom theme from an external directory. They can see these page templates in the wp-admin and they render on the frontend. Everything works fine with this, but I would like to register files from multiple directories, not just one directory.

I need to make $file equal multiple directories. I've tried an array. I've tried && and a couple other things, including the below code, but nothing works. I'm not a pro, but what am I missing here? Can this be done? In the code below I see that the last $file = takes priority over the previous $file =.

So is there a way I can make $file equals multiple paths?

In short, I want $file to consider multiple paths.

The code probably explains itself what I am trying to achieve.

    $file = CUSTOM_OPTION_BACKEND_TEMPLATES_PATH .      '/home/'            . get_post_meta( $post->ID, '_wp_page_template', true );
    $file = CUSTOM_OPTION_BACKEND_TEMPLATES_PATH .      '/pages/'           . get_post_meta( $post->ID, '_wp_page_template', true );
    $file = CUSTOM_OPTION_BACKEND_TEMPLATES_PATH .      '/blog/'            . get_post_meta( $post->ID, '_wp_page_template', true );
    $file = CUSTOM_OPTION_BACKEND_TEMPLATES_PATH .      '/single-posts/'    . get_post_meta( $post->ID, '_wp_page_template', true );
    $file = CUSTOM_OPTION_BACKEND_TEMPLATES_PATH .      '/products/'        . get_post_meta( $post->ID, '_wp_page_template', true );
    $file = CUSTOM_OPTION_BACKEND_TEMPLATES_PATH .      '/templates/'       . get_post_meta( $post->ID, '_wp_page_template', true );
    $file = CUSTOM_OPTION_BACKEND_TEMPLATES_PATH .      '/products/'        . get_post_meta( $post->ID, '_wp_page_template', true );


if ( file_exists( $file ) ) {
    return $file;
} 
Source Link

How to make $file = string, array or multiple values?

I need to make $file equal multiple directories. I've tried an array. I've tried && and a couple other things, including the below code, but nothing works. I'm not a pro, but what am I missing here? Can this be done? In the code below I see that the last $file = takes priority over the previous $file =.

So is there a way I can make $file equals multiple paths?

In short, I want $file to consider multiple paths.

The code probably explains itself what I am trying to achieve.

    $file = CUSTOM_OPTION_BACKEND_TEMPLATES_PATH .      '/home/'            . get_post_meta( $post->ID, '_wp_page_template', true );
    $file = CUSTOM_OPTION_BACKEND_TEMPLATES_PATH .      '/pages/'           . get_post_meta( $post->ID, '_wp_page_template', true );
    $file = CUSTOM_OPTION_BACKEND_TEMPLATES_PATH .      '/blog/'            . get_post_meta( $post->ID, '_wp_page_template', true );
    $file = CUSTOM_OPTION_BACKEND_TEMPLATES_PATH .      '/single-posts/'    . get_post_meta( $post->ID, '_wp_page_template', true );
    $file = CUSTOM_OPTION_BACKEND_TEMPLATES_PATH .      '/products/'        . get_post_meta( $post->ID, '_wp_page_template', true );
    $file = CUSTOM_OPTION_BACKEND_TEMPLATES_PATH .      '/templates/'       . get_post_meta( $post->ID, '_wp_page_template', true );
    $file = CUSTOM_OPTION_BACKEND_TEMPLATES_PATH .      '/products/'        . get_post_meta( $post->ID, '_wp_page_template', true );


if ( file_exists( $file ) ) {
    return $file;
}