Beispiel #1
0
 function load_value($value, $post_id, $field)
 {
     // get valid terms
     $value = acf_get_valid_terms($value, $field['taxonomy']);
     // load/save
     if ($field['load_save_terms']) {
         // bail early if no value
         if (empty($value)) {
             return $value;
         }
         // get current ID's
         $term_ids = wp_get_object_terms($post_id, $field['taxonomy'], array('fields' => 'ids', 'orderby' => 'none'));
         // case
         if (empty($term_ids)) {
             // 1. no terms for this post
             return null;
         } elseif (is_array($value)) {
             // 2. remove metadata terms which are no longer for this post
             $value = array_map('intval', $value);
             $value = array_intersect($value, $term_ids);
         } elseif (!in_array($value, $term_ids)) {
             // 3. term is no longer for this post
             return null;
         }
     }
     // return
     return $value;
 }
Beispiel #2
0
 function load_value($value, $post_id, $field)
 {
     // get valid terms
     $value = acf_get_valid_terms($value, $field['taxonomy']);
     // load/save
     if ($field['load_terms']) {
         // get terms
         $term_ids = wp_get_object_terms($post_id, $field['taxonomy'], array('fields' => 'ids', 'orderby' => 'none'));
         // error
         if (is_wp_error($term_ids)) {
             return false;
         }
         // return
         return $term_ids;
     }
     // return
     return $value;
 }
Beispiel #3
0
 function load_value($value, $post_id, $field)
 {
     // get valid terms
     $value = acf_get_valid_terms($value, $field['taxonomy']);
     // load_terms
     if ($field['load_terms']) {
         // get terms
         $info = acf_get_post_id_info($post_id);
         $term_ids = wp_get_object_terms($info['id'], $field['taxonomy'], array('fields' => 'ids', 'orderby' => 'none'));
         // bail early if no terms
         if (empty($term_ids) || is_wp_error($term_ids)) {
             return false;
         }
         // sort
         if (!empty($value)) {
             $order = array();
             foreach ($term_ids as $i => $v) {
                 $order[$i] = array_search($v, $value);
             }
             array_multisort($order, $term_ids);
         }
         // update value
         $value = $term_ids;
     }
     // convert back from array if neccessary
     if ($field['field_type'] == 'select' || $field['field_type'] == 'radio') {
         $value = array_shift($value);
     }
     // return
     return $value;
 }
 function load_value($value, $post_id, $field)
 {
     // get valid terms
     $value = acf_get_valid_terms($value, $field['taxonomy']);
     // load_terms
     if ($field['load_terms']) {
         // get terms
         $term_ids = wp_get_object_terms($post_id, $field['taxonomy'], array('fields' => 'ids', 'orderby' => 'none'));
         // bail early if no terms
         if (empty($term_ids) || is_wp_error($term_ids)) {
             return false;
         }
         // sort
         if (!empty($value)) {
             $order = array();
             foreach ($term_ids as $i => $v) {
                 $order[$i] = array_search($v, $value);
             }
             array_multisort($order, $term_ids);
         }
         // return
         return $term_ids;
     }
     // return
     return $value;
 }