本文整理汇总了PHP中acf_Field::get_value_for_api方法的典型用法代码示例。如果您正苦于以下问题:PHP acf_Field::get_value_for_api方法的具体用法?PHP acf_Field::get_value_for_api怎么用?PHP acf_Field::get_value_for_api使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类acf_Field
的用法示例。
在下文中一共展示了acf_Field::get_value_for_api方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: get_value_for_api
/**
* 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: get_value_for_api
/**
* 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: get_value_for_api
/**
* 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: get_value_for_api
/**
* 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);
}