Exemple #1
0
 /**
  * Get ACF fields for options in a specific post
  *
  * @param int $post_id Post ID
  * @return array ACF fields
  */
 private function get_fields($post_id)
 {
     $post_id = intval($post_id);
     $post_type = get_post_type($post_id);
     $fields = array();
     // get ACF field groups for this option and post type
     $field_groups = Layotter_ACF::get_filtered_field_groups(array('post_type' => $post_type, 'layotter' => $this->type . '_options'));
     foreach ($field_groups as $field_group) {
         $fields = array_merge($fields, Layotter_ACF::get_fields($field_group));
     }
     return $fields;
 }
Exemple #2
0
 /**
  * Get ACF fields for this element
  *
  * @return array ACF fields
  * @throws Exception If $this->field_group wasn't assigned correctly in $this->attributes()
  */
 protected final function get_fields()
 {
     // ACF field group can be provided as post id (int) or slug ('group_xyz')
     if (!is_int($this->field_group) and !is_string($this->field_group)) {
         throw new Exception('$this->field_group must be assigned in attributes() (error in class ' . get_called_class() . ')');
     }
     if (is_int($this->field_group)) {
         $field_group = Layotter_ACF::get_field_group_by_id($this->field_group);
         $identifier = 'post_id';
     } else {
         $field_group = Layotter_ACF::get_field_group_by_key($this->field_group);
         $identifier = 'acf-field-group';
     }
     // check if the field group exists
     if (!$field_group) {
         throw new Exception('No ACF field group found for ' . $identifier . '=' . $this->field_group . ' (error in class ' . get_called_class() . ')');
     }
     // return fields for the provided ACF field group
     return Layotter_ACF::get_fields($field_group);
 }