0

I couldn't find any help on Google but also because I don't really know how to address this issue in English.

I'm working on a WP theme with Advanced Custom Fields. I need one of the php includes on the page to be a custom field.

How do I do this? I tried this but it doesn't work? I am no expert in this..

<?php $search_form = get_field( 'search_template_include', 'option' ); ?>
<?php include('$search_form'); ?>
3
  • 1
    Do you have an example of what get_field( 'search_template_include', 'option' ); returns? Commented Nov 24, 2016 at 23:16
  • The include function includes a php script with the filename specified. So if your call to get_field returns a filename of an existing php script then this code would be valid. Commented Nov 24, 2016 at 23:16
  • It returns just '' search.php '' (just the text, no quote signs). Wait let me get this straight: the output does work if I just put it somewhere random. But I don't get it to output in the 'include( )' part. Commented Nov 24, 2016 at 23:19

1 Answer 1

1

It took me almost an hour, but this PHP noobie found the answer himself

<?php include( get_field( "search_template_include", "option" ) ); ?>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.