本文整理汇总了PHP中acf_get_pretty_taxonomies函数的典型用法代码示例。如果您正苦于以下问题:PHP acf_get_pretty_taxonomies函数的具体用法?PHP acf_get_pretty_taxonomies怎么用?PHP acf_get_pretty_taxonomies使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了acf_get_pretty_taxonomies函数的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: acf_get_taxonomy_terms
function acf_get_taxonomy_terms($taxonomies = array())
{
// force array
$taxonomies = acf_force_type_array($taxonomies);
// get pretty taxonomy names
$taxonomies = acf_get_pretty_taxonomies($taxonomies);
// vars
$r = array();
// populate $r
foreach (array_keys($taxonomies) as $taxonomy) {
// vars
$label = $taxonomies[$taxonomy];
$terms = get_terms($taxonomy, array('hide_empty' => false));
if (!empty($terms)) {
$r[$label] = array();
foreach ($terms as $term) {
$k = "{$taxonomy}:{$term->slug}";
$r[$label][$k] = $term->name;
}
}
}
// return
return $r;
}
示例2: render_field
function render_field($field)
{
// echo "<pre>";
// print_r($field);
// echo "</pre>";
$taxonomies = array();
$taxonomies = acf_get_array($taxonomies);
$taxonomies = acf_get_pretty_taxonomies($taxonomies);
$all_taxonomies = acf_get_taxonomy_terms();
$selected_taxonomies = array();
$terms = array();
$slug_name = !empty($field['choices']) ? $field['choices'] : array_keys(acf_get_pretty_taxonomies());
foreach ($slug_name as $k1 => $v1) {
$terms = array_merge($terms, get_terms($v1, array('hide_empty' => false)));
foreach ($taxonomies as $k2 => $v2) {
if ($v1 == $k2) {
$field['choices'][$k1] = $v2;
}
}
}
foreach ($field['choices'] as $k1 => $v1) {
foreach ($all_taxonomies as $k2 => $v2) {
if ($v1 == $k2) {
$selected_taxonomies[$v1] = $all_taxonomies[$k2];
}
}
}
$field['choices'] = $selected_taxonomies;
// convert value to array
// $field['value'] = acf_force_type_array($field['value']);
// add empty value (allows '' to be selected)
if (empty($field['value'])) {
$field['value'][''] = '';
$field['value']['cat'] = '';
}
// placeholder
if (empty($field['placeholder'])) {
$field['placeholder'] = __("Select", 'acf');
}
// vars
$atts = array('id' => $field['id'], 'class' => $field['class'] . ' js-multi-taxonomy-select2', 'name' => $field['name'], 'data-ui' => $field['ui'], 'data-ajax' => $field['ajax'], 'data-multiple' => $field['multiple'], 'data-placeholder' => $field['placeholder'], 'data-allow_null' => $field['allow_null']);
// hidden input
if ($field['ui']) {
acf_hidden_input(array('type' => 'hidden', 'id' => $field['id'], 'name' => $field['name'], 'value' => implode(',', $field['value'])));
} elseif ($field['multiple']) {
acf_hidden_input(array('type' => 'hidden', 'name' => $field['name']));
}
// ui
if ($field['ui']) {
$atts['disabled'] = 'disabled';
$atts['class'] .= ' acf-hidden';
}
// multiple
if ($field['multiple']) {
$atts['multiple'] = 'multiple';
$atts['size'] = 5;
$atts['name'] .= '[]';
}
// special atts
foreach (array('readonly', 'disabled') as $k) {
if (!empty($field[$k])) {
$atts[$k] = $k;
}
}
// vars
$els = array();
$choices = array();
if ($field['data_type']) {
// loop through values and add them as options
if (!empty($field['choices'])) {
foreach ($field['choices'] as $k => $v) {
if (is_array($v)) {
// optgroup
$els[] = array('type' => 'optgroup', 'label' => $k);
if (!empty($v)) {
foreach ($v as $k2 => $v2) {
if ($field['type_value']) {
foreach ($terms as $key => $val) {
if ($val->name == $v2) {
$els[] = array('type' => 'option', 'value' => $val->term_id, 'label' => $v2, 'selected' => $slct = $val->term_id == $field['value'] ? "selected" : "");
}
}
} else {
$els[] = array('type' => 'option', 'value' => $k2, 'label' => $v2, 'selected' => $slct = $k2 == $field['value'] ? "selected" : "");
}
$choices[] = $k2;
}
}
$els[] = array('type' => '/optgroup');
} else {
$els[] = array('type' => 'option', 'value' => $k, 'label' => $v, 'selected' => $slct = $k == $field['value'] ? "selected" : "");
$choices[] = $k;
}
}
}
// null
if ($field['allow_null']) {
array_unshift($els, array('type' => 'option', 'value' => '', 'label' => '- ' . $field['placeholder'] . ' -'));
}
// html
//.........这里部分代码省略.........
示例3: acf_get_taxonomy_terms
function acf_get_taxonomy_terms($taxonomies = array())
{
// force array
$taxonomies = acf_get_array($taxonomies);
// get pretty taxonomy names
$taxonomies = acf_get_pretty_taxonomies($taxonomies);
// vars
$r = array();
// populate $r
foreach (array_keys($taxonomies) as $taxonomy) {
// vars
$label = $taxonomies[$taxonomy];
$terms = get_terms($taxonomy, array('hide_empty' => false));
$is_hierarchical = is_taxonomy_hierarchical($taxonomy);
// bail early i no terms
if (empty($terms)) {
continue;
}
// sort into hierachial order!
if ($is_hierarchical) {
$terms = _get_term_children(0, $terms, $taxonomy);
}
// add placeholder
$r[$label] = array();
// add choices
foreach ($terms as $term) {
$k = "{$taxonomy}:{$term->slug}";
$r[$label][$k] = acf_get_term_title($term);
}
}
// return
return $r;
}
示例4: render_field
function render_field($field)
{
$taxonomies = array();
$taxonomies = acf_get_array($taxonomies);
$taxonomies = acf_get_pretty_taxonomies($taxonomies);
$taxonomy_terms = acf_get_taxonomy_terms();
$selected_taxonomies = array();
$terms = array();
$slug_name = !empty($field['choices']) ? $field['choices'] : array_keys(acf_get_pretty_taxonomies());
if ($field['tax_type'] == 'Term') {
// select terms
foreach ($slug_name as $k1 => $v1) {
$terms = array_merge($terms, get_terms($v1, array('hide_empty' => false)));
foreach ($taxonomies as $k2 => $v2) {
if ($v1 == $k2) {
$field['choices'][$k1] = $v2;
}
}
}
foreach ($field['choices'] as $k1 => $v1) {
foreach ($taxonomy_terms as $k2 => $v2) {
if ($v1 == $k2) {
$selected_taxonomies[$v1] = $taxonomy_terms[$k2];
}
}
}
} else {
//select taxonomies
$taxonomies = array();
foreach ($slug_name as $tax_name) {
// only use allowed taxonomies
$taxonomies[$tax_name] = get_taxonomy($tax_name);
}
foreach ($taxonomies as $taxonomy) {
$selected_taxonomies[$taxonomy->name] = $taxonomy->label;
}
}
$field['choices'] = $selected_taxonomies;
// add empty value (allows '' to be selected)
if (empty($field['value'])) {
$field['value'] = '';
$field['value']['cat'] = '';
}
// placeholder
if (empty($field['placeholder'])) {
$field['placeholder'] = __("Select", 'acf');
}
// vars
$atts = array('id' => $field['id'], 'class' => $field['class'] . ' js-multi-taxonomy-select2', 'name' => $field['name'], 'data-ui' => $field['ui'], 'data-ajax' => $field['ajax'], 'data-placeholder' => $field['placeholder'], 'data-allow_null' => $field['allow_null']);
// hidden input
if ($field['ui']) {
acf_hidden_input(array('type' => 'hidden', 'id' => $field['id'], 'name' => $field['name'], 'value' => implode(',', $field['value'])));
} elseif ($field['multiple']) {
acf_hidden_input(array('type' => 'hidden', 'name' => $field['name']));
}
// ui
if ($field['ui']) {
$atts['disabled'] = 'disabled';
$atts['class'] .= ' acf-hidden';
}
// special atts
foreach (array('readonly', 'disabled') as $k) {
if (!empty($field[$k])) {
$atts[$k] = $k;
}
}
// vars
$els = array();
$choices = array();
// loop through values and add them as options
if (!empty($field['choices'])) {
foreach ($field['choices'] as $k => $v) {
// allowed taxonomies
if (is_array($v)) {
// optgroup
$els[] = array('type' => 'optgroup', 'label' => $k);
if (!empty($v)) {
foreach ($v as $k2 => $v2) {
$strip_v2_hyphen = preg_replace('#-\\s?#', '', $v2);
// Child categories have hyphens before the name, we need to remove them in order to match them
if ($field['type_value']) {
// value = term ID
foreach ($terms as $key => $val) {
if ($val->name == $strip_v2_hyphen) {
$els[] = array('type' => 'option', 'value' => $val->term_id, 'label' => $v2, 'selected' => $slct = $val->term_id == $field['value'] ? "selected" : "");
}
}
} else {
// value = term slug
preg_match('#(?::)(.*)#', $k2, $value);
// originally returns 'taxonomy:term-slug' this removes 'taxonomy:'
$els[] = array('type' => 'option', 'value' => $value[1], 'label' => $v2, 'selected' => $slct = $value[1] == $field['value'] ? "selected" : "");
}
$choices[] = $k2;
}
}
$els[] = array('type' => '/optgroup');
} else {
// value = Taxonomy Slug
$els[] = array('type' => 'option', 'value' => $k, 'label' => $v, 'selected' => $slct = $k == $field['value'] ? "selected" : "");
//.........这里部分代码省略.........