Hey All!
I have a bit of a PHP question about using a custom field in a IF statement and then in a require_once.
Here is my issue…
I am using the following IF statement:
<?php
if(get_field('CUSTOM_FIELD'))
{
echo '<p>' . get_field('CUSTOM_FIELD') . '</p>';
}
?>
However I would like to create a IF statement that will then trigger a require_once action that uses the custom field as the file name.
Example:
<?php
require_once $_SERVER['DOCUMENT_ROOT'] . '/files/CUSTOM_FIELD.php';
?>
Any guidance on this would be really appreciated!
With some help from the guys on the WP forum I managed to get this working. I have shared the code below incase anybody needs it in the future.
<?php
$field = get_field('CUSTOM_FIELD');
if ($field) {
$file = $_SERVER['DOCUMENT_ROOT'] . '/files/' . $field . '.php';
require_once( $file);
}
?>