The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums Back End ACF – display image on selection

  • This topic is empty.
Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
  • #201279

    I have created a custom field (activity_rating) using ACF with a selection 1, 2, 3, 4, 5 (it’s to show activity rating of holidays – 1 being very east and 5 being very difficult).

    If, for example, 1 is selected I would like to display a corresponding image (e.g. image showing 1 out of 5 stars – i.e. very easy). I’m guessing I can just repeat the code for activity levels 2-5 and associated images- but with different image urls

    Any ideas very very much appreciated.


    My PHP isn’t that great, so take this with a grain of salt: but I would think a simple elseif flow could work. I first thought of a switch, but not sure how each case would line up with each rating.

    $rating = get_field('activity_rating);
    if ($rating == 1):
      $img_url = 'bloginfo("template_directory_uri()/img/1.jpg")';
    elseif ($rating == 2):
      $img_url = 'bloginfo("template_directory_uri()/img/2.jpg")';

    Or, rather than passing the entire image url to $img_url, you could just do: $img_url = "img/rating-1.jpg";, but that depends on what your markup is like.

Viewing 2 posts - 1 through 2 (of 2 total)
  • The forum ‘Back End’ is closed to new topics and replies.