Support

Account

Home Forums ACF PRO Fetch ACF field dynamically

Unread

Fetch ACF field dynamically

  • Hello,

    I have a custom post type, with a custom taxonomy (services). I need to assign a price to each service, that is unique, per post.

    I created a group on the post type, where the field names match the names of the taxonomy term that I would like to display them next to.

    Then on the front end I am trying list the services, with their unique price.

    I have tried doing this, but I get ‘Warning: Undefined array key’

    <?php
      $prices = get_field('service_prices');
      $service_name = strtolower(str_replace(' ', '_', $service->name));
    if ($prices):
    ?>
    	<div>
    		<?= $prices[$service_name]; ?>
    	</div>
    <?php endif; ?>

    How would I successfully go about doing something like this? My $service_name is outputting the correct ACF field name.

Viewing 1 post (of 1 total)

You must be logged in to reply to this topic.