コード例 #1
0
 /**
  * Returns the value of the field for the advanced custom fields API
  *
  * @see acf_Field::get_value_for_api()
  * @param int $post_id
  * @param array $field
  * @return string
  */
 public function get_value_for_api($post_id, $field)
 {
     $this->set_field_defaults($field);
     //If terms are set on the post, we can let WordPress create the list
     if ($field['set_post_terms']) {
         return get_the_term_list($post_id, $field['taxonomy']);
     }
     //Otherwise, loop through the terms
     $value = parent::get_value_for_api($post_id, $field);
     if (empty($value)) {
         return false;
     }
     $format = isset($field['save_format']) ? $field['save_format'] : 'html';
     $returned_terms = array();
     foreach ($value as $term_id) {
         $term_id = intval($term_id);
         $term = get_term($term_id, $field['taxonomy']);
         if (!$term or is_wp_error($term)) {
             continue;
         }
         if ($format == 'html') {
             $link = get_term_link($term, $field['taxonomy']);
             if (!is_wp_error($link)) {
                 $returned_terms[] = '<a href="' . $link . '" rel="tag">' . $term->name . '</a>';
             }
         } elseif ($format == 'id') {
             $returned_terms[] = $term->term_id;
         } elseif ($format == 'object') {
             $returned_terms[] = $term;
         }
     }
     if (empty($returned_terms)) {
         return false;
     }
     if ($format == 'html') {
         //Allow plugins to modify
         $returned_terms = apply_filters("term_links-{$field['taxonomy']}", $returned_terms);
         return join('', $returned_terms);
     } else {
         return $returned_terms;
     }
 }
コード例 #2
0
 /**
  * Returns the value of the field for the advanced custom fields API
  * 
  * @see acf_Field::get_value_for_api()
  * @param int $post_id
  * @param array $field
  * @return string
  */
 public function get_value_for_api($post_id, $field)
 {
     return parent::get_value_for_api($post_id, $field);
 }
コード例 #3
0
ファイル: taxonomy-field.php プロジェクト: Calraiser/flux
 /**
  * Returns the value of the field for the advanced custom fields API
  *
  * @see acf_Field::get_value_for_api()
  * @param int $post_id
  * @param array $field
  * @return string
  */
 public function get_value_for_api($post_id, $field)
 {
     $this->set_field_defaults($field);
     $value = parent::get_value_for_api($post_id, $field);
     $value = is_array($value) ? $value : array();
     $terms = array();
     foreach ($value as $term_id) {
         $term_id = intval($term_id);
         switch ($field[self::FIELD_RETURN_TYPE]) {
             case self::RETURN_TYPE_ID:
                 $terms[] = $term_id;
                 break;
             case self::RETURN_TYPE_OBJECT:
                 $terms[] = get_term($term_id, $field[self::FIELD_TAXONOMY]);
                 break;
             case self::RETURN_TYPE_LINK:
                 $term = get_term($term_id, $field[self::FIELD_TAXONOMY]);
                 $terms[] = sprintf('<a href="%1$s" rel="tag">%2$s</a>', esc_attr(get_term_link($term, $field[self::FIELD_TAXONOMY])), esc_html($term->name));
                 break;
         }
     }
     switch ($field[self::FIELD_RETURN_TYPE]) {
         case self::RETURN_TYPE_ID:
         case self::RETURN_TYPE_OBJECT:
             return $terms;
         case self::RETURN_TYPE_LINK:
             //Allow plugins to modify
             $terms = apply_filters("term_links-{$field[self::FIELD_TAXONOMY]}", $terms);
             return implode('', $terms);
     }
     return false;
 }
コード例 #4
0
 /**
  * Returns the value of the field for the advanced custom fields API
  * 
  * @see acf_Field::get_value_for_api()
  * @param int $post_id
  * @param array $field
  */
 public function get_value_for_api($post_id, $field)
 {
     $this->set_field_defaults($field);
     if ($acf = $this->get_acf()) {
         return $acf->fields[$field['required_type']]->get_value_for_api($post_id, $field);
     }
     return parent::get_value_for_api($post_id, $field);
 }