Load ACF Theme Option into Another ACF Field

Load ACF Theme Option into Another ACF Field

There are scenarios where we need to add data at one place and utilize it at multiple place. Like we have a list of Hotels (Stays) where we want to showcase different amenities selecting one or more than one amenity from the backend however these set of amenities list remains same across all Stays in future there may be a need to introduce couple of new Amenities which can be added at central place in theme options.

  • Global Option to add Amenities.

screen138

screen139

/*Overide Amenities for Accomodations and Restaurants from Theme Option*/
function amenities_load_field( $field ) {
    $theme_options = get_field('amenities_lists', 'option');
        $options = array();
        if ($theme_options) {
            foreach ($theme_options as $option) {
                $option_name    = $option['amenity_name'];
                $option_value   = $option['amenity_icon']['url'];
                $options[$option_value] = $option_name;
            }
        }
        $field['choices'] = $options;
    return $field;
}
add_filter('acf/load_field/name=amenities', 'amenities_load_field');
  • Create Field in Another Location Like in any Custom Post Type

screen141

screen140

  • The Output on View JS

screen142

Leave a Reply

Your email address will not be published. Required fields are marked *