top of page

Load ACF Theme Option into Another ACF Field

  • Writer: سُلَيْمَان بْن دَاوُوْد
    سُلَيْمَان بْن دَاوُوْد
  • Jun 12, 2023
  • 1 min read

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.


/*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


  • The Output on View JS



 
 
 

Recent Posts

See All
Duplicate Category in Wordpress

The following code helps to duplicate the default wordpress category by help of code. // Add Duplicate option for categories in WordPress...

 
 
 
C#.NET and Its Associated Codes

1- Creating an Desktop Application in C#.NET C# ADO.NET & MySQL MAIN C# and MySQL ADO.NET with Crystals Reports Ready Code 2- Handling...

 
 
 

Comments


© 2020 by syednazrulhassan

bottom of page