Support

Account

Home Forums Front-end Issues Kindly help with display question

Solved

Kindly help with display question

  • 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

  • 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: http://php.net/manual/en/language.variables.scope.php).

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

     the_field('instructor_organization');
    // 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.

  • @elliot
    @wells5609

    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)

The topic ‘Kindly help with display question’ is closed to new replies.