Home Forums Front-end Issues Kindly help with display question


Kindly help with display question

    • tmbond

    • August 16, 2013 at 9:49 am

    Hello All,

    My field name is {{instructor_organization}}

    I added the below code to my function.php file:

    <?php $instructor_organization = get_field($instructor_organization, $post_id, $format_value); ?>

    To display it, I then added the below code to a page called single-event.php:

    <?php the_field($instructor_organization, $post_id); ?>

    But it is not showing when I view the front end. What am I missing? I am new to PHP. Any help would be appreciated. Kindly tell me what I should put and where

    • Elliot

    • August 16, 2013 at 2:40 pm

    Hi @tmbond

    Chances are you are miss-using the 2nd and 3rd parameters.

    Have you tried just:
    <?php the_field($instructor_organization); ?>

  • @tmbond

    I think the issue is that you’re trying to reference a variable in single-event.php ($instructor_organization) which is defined in functions.php – this is because the variable is “out of scope” (see:

    You’ll need something like this in single-event.php:

    // OR
    echo get_field('instructor_organization');

    Both output the field value. Alternatively, you could do:

     // in functions.php:
    function get_instructor_org($post_id){
      $org = get_field('instructor_organization', $post_id);
      return $org;
    // then in single-event.php:
    // assuming you're in the Loop (i.e. $post variable is available)
    echo get_instructor_org($post->ID);

    Obviously the first way is easier, but the second gives you an idea of how variables can be passed to functions.

    • tmbond

    • August 21, 2013 at 2:49 am


    Thanks for your responses. Sorry for not responding to you sooner. Now, I actually had it done in a different way. But I am going to try your code suggestions to see how they work in case of a future need. Thanks again.

Viewing 4 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic.

We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.