function acf_location_rule_values_category_ancestor($choices)
{
    // copied from acf rules values for post_category
    $terms = acf_get_taxonomy_terms('category');
    if (!empty($terms)) {
        $choices = array_pop($terms);
    }
    return $choices;
}
示例#2
0
 function render_location_value($options)
 {
     // vars
     $options = wp_parse_args($options, array('group_id' => 0, 'rule_id' => 0, 'value' => null, 'param' => null));
     // vars
     $choices = array();
     // some case's have the same outcome
     if ($options['param'] == "page_parent") {
         $options['param'] = "page";
     }
     switch ($options['param']) {
         /*
          *  Basic
          */
         case "post_type":
             // all post types except attachment
             $exclude = array('attachment');
             $choices = acf_get_post_types($exclude);
             $choices = acf_get_pretty_post_types($choices);
             break;
         case "user_type":
             global $wp_roles;
             $choices = $wp_roles->get_names();
             if (is_multisite()) {
                 $choices['super_admin'] = __('Super Admin');
             }
             break;
             /*
              *  Post
              */
         /*
          *  Post
          */
         case "post":
             // get post types
             $exclude = array('page', 'attachment');
             $post_types = acf_get_post_types($exclude);
             // get posts grouped by post type
             $groups = acf_get_posts(array('post_type' => $post_types));
             if (!empty($groups)) {
                 foreach (array_keys($groups) as $group_title) {
                     // vars
                     $posts = acf_extract_var($groups, $group_title);
                     // override post data
                     foreach (array_keys($posts) as $post_id) {
                         // update
                         $posts[$post_id] = acf_get_post_title($posts[$post_id]);
                     }
                     // append to $choices
                     $choices[$group_title] = $posts;
                 }
             }
             break;
         case "post_category":
             $terms = acf_get_taxonomy_terms('category');
             if (!empty($terms)) {
                 $choices = array_pop($terms);
             }
             break;
         case "post_format":
             $choices = get_post_format_strings();
             break;
         case "post_status":
             $choices = array('publish' => __('Publish', 'acf'), 'pending' => __('Pending Review', 'acf'), 'draft' => __('Draft', 'acf'), 'future' => __('Future', 'acf'), 'private' => __('Private', 'acf'), 'inherit' => __('Revision', 'acf'), 'trash' => __('Trash', 'acf'));
             break;
         case "post_taxonomy":
             $choices = acf_get_taxonomy_terms();
             // unset post_format
             if (isset($choices['post_format'])) {
                 unset($choices['post_format']);
             }
             break;
             /*
              *  Page
              */
         /*
          *  Page
          */
         case "page":
             // get posts grouped by post type
             $groups = acf_get_posts(array('post_type' => 'page'));
             if (!empty($groups)) {
                 foreach (array_keys($groups) as $group_title) {
                     // vars
                     $posts = acf_extract_var($groups, $group_title);
                     // override post data
                     foreach (array_keys($posts) as $post_id) {
                         // update
                         $posts[$post_id] = acf_get_post_title($posts[$post_id]);
                     }
                     // append to $choices
                     $choices = $posts;
                 }
             }
             break;
         case "page_type":
             $choices = array('front_page' => __("Front Page", 'acf'), 'posts_page' => __("Posts Page", 'acf'), 'top_level' => __("Top Level Page (parent of 0)", 'acf'), 'parent' => __("Parent Page (has children)", 'acf'), 'child' => __("Child Page (has parent)", 'acf'));
             break;
         case "page_parent":
             // refer to "page"
             break;
         case "page_template":
             $choices = array('default' => __("Default Template", 'acf'));
             $templates = get_page_templates();
             foreach ($templates as $k => $v) {
                 $choices[$v] = $k;
             }
             break;
             /*
              *  User
              */
         /*
          *  User
          */
         case "user_role":
             global $wp_roles;
             $choices = array_merge(array('all' => __('All', 'acf')), $wp_roles->get_names());
             break;
         case "user_form":
             $choices = array('all' => __('All', 'acf'), 'edit' => __('Add / Edit', 'acf'), 'register' => __('Register', 'acf'));
             break;
             /*
              *  Forms
              */
         /*
          *  Forms
          */
         case "attachment":
             $choices = array('all' => __('All', 'acf'));
             break;
         case "taxonomy":
             $choices = array_merge(array('all' => __('All', 'acf')), acf_get_taxonomies());
             // unset post_format
             if (isset($choices['post_format'])) {
                 unset($choices['post_format']);
             }
             break;
         case "comment":
             $choices = array('all' => __('All', 'acf'));
             break;
         case "widget":
             global $wp_widget_factory;
             $choices = array('all' => __('All', 'acf'));
             if (!empty($wp_widget_factory->widgets)) {
                 foreach ($wp_widget_factory->widgets as $widget) {
                     $choices[$widget->id_base] = $widget->name;
                 }
             }
             break;
     }
     // allow custom location rules
     $choices = apply_filters('acf/location/rule_values/' . $options['param'], $choices);
     // create field
     acf_render_field(array('type' => 'select', 'prefix' => "acf_field_group[location][{$options['group_id']}][{$options['rule_id']}]", 'name' => 'value', 'value' => $options['value'], 'choices' => $choices));
 }
示例#3
0
function acf_decode_taxonomy_terms($terms = false)
{
    // load all taxonomies if not specified in args
    if (!$terms) {
        $terms = acf_get_taxonomy_terms();
    }
    // vars
    $r = array();
    foreach ($terms as $term) {
        // vars
        $data = acf_decode_taxonomy_term($term);
        // create empty array
        if (!array_key_exists($data['taxonomy'], $r)) {
            $r[$data['taxonomy']] = array();
        }
        // append to taxonomy
        $r[$data['taxonomy']][] = $data['term'];
    }
    // return
    return $r;
}
示例#4
0
 function render_field_settings($field)
 {
     // vars
     $field['min'] = empty($field['min']) ? '' : $field['min'];
     $field['max'] = empty($field['max']) ? '' : $field['max'];
     // post_type
     acf_render_field_setting($field, array('label' => __('Filter by Post Type', 'acf'), 'instructions' => '', 'type' => 'select', 'name' => 'post_type', 'choices' => acf_get_pretty_post_types(), 'multiple' => 1, 'ui' => 1, 'allow_null' => 1, 'placeholder' => __("All post types", 'acf')));
     // taxonomy
     acf_render_field_setting($field, array('label' => __('Filter by Taxonomy', 'acf'), 'instructions' => '', 'type' => 'select', 'name' => 'taxonomy', 'choices' => acf_get_taxonomy_terms(), 'multiple' => 1, 'ui' => 1, 'allow_null' => 1, 'placeholder' => __("All taxonomies", 'acf')));
     // filters
     acf_render_field_setting($field, array('label' => __('Filters', 'acf'), 'instructions' => '', 'type' => 'checkbox', 'name' => 'filters', 'choices' => array('search' => __("Search", 'acf'), 'post_type' => __("Post Type", 'acf'), 'taxonomy' => __("Taxonomy", 'acf'))));
     // filters
     acf_render_field_setting($field, array('label' => __('Elements', 'acf'), 'instructions' => __('Selected elements will be displayed in each result', 'acf'), 'type' => 'checkbox', 'name' => 'elements', 'choices' => array('featured_image' => __("Featured Image", 'acf'))));
     // min
     acf_render_field_setting($field, array('label' => __('Minimum posts', 'acf'), 'instructions' => '', 'type' => 'number', 'name' => 'min'));
     // max
     acf_render_field_setting($field, array('label' => __('Maximum posts', 'acf'), 'instructions' => '', 'type' => 'number', 'name' => 'max'));
     // return_format
     acf_render_field_setting($field, array('label' => __('Return Format', 'acf'), 'instructions' => '', 'type' => 'radio', 'name' => 'return_format', 'choices' => array('object' => __("Post Object", 'acf'), 'id' => __("Post ID", 'acf')), 'layout' => 'horizontal'));
 }
示例#5
0
 function render_field_settings($field)
 {
     // post_type
     acf_render_field_setting($field, array('label' => __('Filter by Post Type', 'acf'), 'instructions' => '', 'type' => 'select', 'name' => 'post_type', 'choices' => acf_get_pretty_post_types(), 'multiple' => 1, 'ui' => 1, 'allow_null' => 1, 'placeholder' => __("All post types", 'acf')));
     // taxonomy
     acf_render_field_setting($field, array('label' => __('Filter by Taxonomy', 'acf'), 'instructions' => '', 'type' => 'select', 'name' => 'taxonomy', 'choices' => acf_get_taxonomy_terms(), 'multiple' => 1, 'ui' => 1, 'allow_null' => 1, 'placeholder' => __("All taxonomies", 'acf')));
     // allow_null
     acf_render_field_setting($field, array('label' => __('Allow Null?', 'acf'), 'instructions' => '', 'type' => 'radio', 'name' => 'allow_null', 'choices' => array(1 => __("Yes", 'acf'), 0 => __("No", 'acf')), 'layout' => 'horizontal'));
     // multiple
     acf_render_field_setting($field, array('label' => __('Select multiple values?', 'acf'), 'instructions' => '', 'type' => 'radio', 'name' => 'multiple', 'choices' => array(1 => __("Yes", 'acf'), 0 => __("No", 'acf')), 'layout' => 'horizontal'));
 }
    function render_field($field)
    {
        switch_to_blog($field['site']);
        echo '<p>' . __('You are looking on posts from site', 'acf-relationship-multisite') . ' <strong>' . get_bloginfo('name') . '</strong></p>';
        restore_current_blog();
        // vars
        $values = array();
        $atts = array('id' => $field['id'], 'class' => "acf-relationship {$field['class']}", 'data-max' => $field['max'], 'data-s' => '', 'data-post_type' => '', 'data-taxonomy' => '', 'data-paged' => 1);
        // Lang
        if (defined('ICL_LANGUAGE_CODE')) {
            $atts['data-lang'] = ICL_LANGUAGE_CODE;
        }
        // data types
        $field['post_type'] = dhz_get_array($field['post_type']);
        $field['taxonomy'] = dhz_get_array($field['taxonomy']);
        // post_types
        $post_types = array();
        if (!empty($field['post_type'])) {
            $post_types = $field['post_type'];
        } else {
            $post_types = acf_get_post_types();
        }
        $post_types = acf_get_pretty_post_types($post_types);
        // taxonomies
        $taxonomies = array();
        if (!empty($field['taxonomy'])) {
            // get the field's terms
            $term_groups = dhz_get_array($field['taxonomy']);
            $term_groups = acf_decode_taxonomy_terms($term_groups);
            // update taxonomies
            $taxonomies = array_keys($term_groups);
        } elseif (!empty($field['post_type'])) {
            // loop over post types and find connected taxonomies
            foreach ($field['post_type'] as $post_type) {
                $post_taxonomies = get_object_taxonomies($post_type);
                // bail early if no taxonomies
                if (empty($post_taxonomies)) {
                    continue;
                }
                foreach ($post_taxonomies as $post_taxonomy) {
                    if (!in_array($post_taxonomy, $taxonomies)) {
                        $taxonomies[] = $post_taxonomy;
                    }
                }
            }
        } else {
            $taxonomies = acf_get_taxonomies();
        }
        // terms
        $term_groups = acf_get_taxonomy_terms($taxonomies);
        // update $term_groups with specific terms
        if (!empty($field['taxonomy'])) {
            foreach (array_keys($term_groups) as $taxonomy) {
                foreach (array_keys($term_groups[$taxonomy]) as $term) {
                    if (!in_array($term, $field['taxonomy'])) {
                        unset($term_groups[$taxonomy][$term]);
                    }
                }
            }
        }
        // width for select filters
        $width = array('search' => 0, 'post_type' => 0, 'taxonomy' => 0);
        if (!empty($field['filters'])) {
            $width = array('search' => 50, 'post_type' => 25, 'taxonomy' => 25);
            foreach (array_keys($width) as $k) {
                if (!in_array($k, $field['filters'])) {
                    $width[$k] = 0;
                }
            }
            // search
            if ($width['search'] == 0) {
                $width['post_type'] = $width['post_type'] == 0 ? 0 : 50;
                $width['taxonomy'] = $width['taxonomy'] == 0 ? 0 : 50;
            }
            // post_type
            if ($width['post_type'] == 0) {
                $width['taxonomy'] = $width['taxonomy'] == 0 ? 0 : 50;
            }
            // taxonomy
            if ($width['taxonomy'] == 0) {
                $width['post_type'] = $width['post_type'] == 0 ? 0 : 50;
            }
            // search
            if ($width['post_type'] == 0 && $width['taxonomy'] == 0) {
                $width['search'] = $width['search'] == 0 ? 0 : 100;
            }
        }
        ?>
<div <?php 
        acf_esc_attr_e($atts);
        ?>
>
	
	<div class="acf-hidden">
		<input type="hidden" name="<?php 
        echo $field['name'];
        ?>
" value="" />
	</div>
	
	<?php 
        if ($width['search'] > 0 || $width['post_type'] > 0 || $width['taxonomy'] > 0) {
            ?>
	<div class="filters">
		
		<ul class="acf-hl">
		
			<?php 
            if ($width['search'] > 0) {
                ?>
			<li style="width:<?php 
                echo $width['search'];
                ?>
%;">
				<div class="inner">
				<input class="filter" data-filter="s" placeholder="<?php 
                _e("Search...", 'acf');
                ?>
" type="text" />
				</div>
			</li>
			<?php 
            }
            ?>
			
			<?php 
            if ($width['post_type'] > 0) {
                ?>
			<li style="width:<?php 
                echo $width['post_type'];
                ?>
%;">
				<div class="inner">
				<select class="filter" data-filter="post_type">
					<option value=""><?php 
                _e('Select post type', 'acf');
                ?>
</option>
					<?php 
                foreach ($post_types as $k => $v) {
                    ?>
						<option value="<?php 
                    echo $k;
                    ?>
"><?php 
                    echo $v;
                    ?>
</option>
					<?php 
                }
                ?>
				</select>
				</div>
			</li>
			<?php 
            }
            ?>
			
			<?php 
            if ($width['taxonomy'] > 0) {
                ?>
			<li style="width:<?php 
                echo $width['taxonomy'];
                ?>
%;">
				<div class="inner">
				<select class="filter" data-filter="taxonomy">
					<option value=""><?php 
                _e('Select taxonomy', 'acf');
                ?>
</option>
					<?php 
                foreach ($term_groups as $k_opt => $v_opt) {
                    ?>
						<optgroup label="<?php 
                    echo $k_opt;
                    ?>
">
							<?php 
                    foreach ($v_opt as $k => $v) {
                        ?>
								<option value="<?php 
                        echo $k;
                        ?>
"><?php 
                        echo $v;
                        ?>
</option>
							<?php 
                    }
                    ?>
						</optgroup>
					<?php 
                }
                ?>
				</select>
				</div>
			</li>
			<?php 
            }
            ?>
		</ul>
		
	</div>
	<?php 
        }
        ?>
	
	<div class="selection acf-cf">
	
		<div class="choices">
		
			<ul class="acf-bl list"></ul>
			
		</div>
		
		<div class="values">
		
			<ul class="acf-bl list">
			
				<?php 
        if (!empty($field['value'])) {
            // get posts
            switch_to_blog($field['site']);
            $posts = $this->get_posts($field['value']);
            // set choices
            if (!empty($posts)) {
                foreach (array_keys($posts) as $i) {
                    // vars
                    $post = acf_extract_var($posts, $i);
                    ?>
<li>
								<input type="hidden" name="<?php 
                    echo $field['name'];
                    ?>
[]" value="<?php 
                    echo $post->ID;
                    ?>
" />
								<span data-id="<?php 
                    echo $post->ID;
                    ?>
" class="acf-rel-item">
									<?php 
                    echo $this->get_post_title($post, $field);
                    ?>
									<a href="#" class="acf-icon small dark" data-name="remove_item"><i class="acf-sprite-remove"></i></a>
								</span>
							</li><?php 
                }
            }
            restore_current_blog();
        }
        ?>
				
			</ul>
			
		</div>
		
	</div>
	
</div>
		<?php 
    }
示例#7
0
 function render_field_settings($field)
 {
     // post_type
     acf_render_field_setting($field, array('label' => __('Filter by Post Type', 'acf'), 'instructions' => '', 'type' => 'select', 'name' => 'post_type', 'choices' => acf_get_pretty_post_types(), 'multiple' => 1, 'ui' => 1, 'allow_null' => 1, 'placeholder' => __("All post types", 'acf')));
     // taxonomy
     acf_render_field_setting($field, array('label' => __('Filter by Taxonomy', 'acf'), 'instructions' => '', 'type' => 'select', 'name' => 'taxonomy', 'choices' => acf_get_taxonomy_terms(), 'multiple' => 1, 'ui' => 1, 'allow_null' => 1, 'placeholder' => __("All taxonomies", 'acf')));
     // allow_null
     acf_render_field_setting($field, array('label' => __('Allow Null?', 'acf'), 'instructions' => '', 'name' => 'allow_null', 'type' => 'true_false', 'ui' => 1));
     // allow_archives
     acf_render_field_setting($field, array('label' => __('Allow Archives URLs', 'acf'), 'instructions' => '', 'name' => 'allow_archives', 'type' => 'true_false', 'ui' => 1));
     // multiple
     acf_render_field_setting($field, array('label' => __('Select multiple values?', 'acf'), 'instructions' => '', 'name' => 'multiple', 'type' => 'true_false', 'ui' => 1));
 }
示例#8
0
            $post_taxonomies = get_object_taxonomies($post_type);
            // bail early if no taxonomies
            if (empty($post_taxonomies)) {
                continue;
            }
            foreach ($post_taxonomies as $post_taxonomy) {
                if (!in_array($post_taxonomy, $taxonomies)) {
                    $taxonomies[] = $post_taxonomy;
                }
            }
        }
    } else {
        $taxonomies = acf_get_taxonomies();
    }
    // terms
    $term_groups = acf_get_taxonomy_terms($taxonomies);
    // update $term_groups with specific terms
    if (!empty($field['taxonomy'])) {
        foreach (array_keys($term_groups) as $taxonomy) {
            foreach (array_keys($term_groups[$taxonomy]) as $term) {
                if (!in_array($term, $field['taxonomy'])) {
                    unset($term_groups[$taxonomy][$term]);
                }
            }
        }
    }
}
// end taxonomy filter
?>
<div <?php 
acf_esc_attr_e($atts);
    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
            echo '<select ' . acf_esc_attr($atts) . '>';
            // construct html
            if (!empty($els)) {
                foreach ($els as $el) {
                    // extract type
                    $type = acf_extract_var($el, 'type');
                    if ($type == 'option') {
                        // get label
                        $label = acf_extract_var($el, 'label');
                        // validate selected
                        if (acf_extract_var($el, 'selected')) {
                            $el['selected'] = 'selected';
                        }
                        echo acf_esc_attr($el);
                        echo '<option ' . acf_esc_attr($el) . '>' . $label . '</option>';
                    } else {
                        echo '<' . $type . ' ' . acf_esc_attr($el) . '>';
                    }
                }
            }
            echo '</select>';
        } else {
            $els = '[';
            $i = 0;
            foreach ($field['choices'] as $k => $v) {
                if (is_array($v)) {
                    $els .= '[';
                    foreach ($v as $k2 => $v2) {
                        foreach ($terms as $key => $val) {
                            if ($val->name == $v2) {
                                $els .= '["' . $v2 . '","' . $val->term_id . '",' . '"' . $slug_name[$i] . '"],';
                            }
                        }
                    }
                    $els .= '],';
                }
                $i++;
            }
            $els .= ']';
            echo '<div class="h">';
            echo '<div class="Taxonomies">';
            echo '<label class="" for="' . $field['key'] . '">Taxonomies</label> ';
            echo '<select class="js-multi-taxonomy-select2 taxonomiesF"  name="' . $field['name'] . '" id="' . $field['key'] . '-taxonomies">';
            $i = 0;
            foreach ($field['choices'] as $k => $v) {
                echo '<option value="' . $i++ . '">' . $k . '</option>';
            }
            echo '</select>';
            echo '</div>';
            echo '<div class="Terms">';
            echo '<label class="" >Terms</label> ';
            echo '<input name="' . $field['name'] . '[cat]" id="' . $field['key'] . '-terms" class="js-multi-taxonomy-select2 termsF" value="" />';
            echo '</div>';
            echo '</div>';
            // }
            echo '
			<script>
				(function($){

					var arr = ' . $els . ';

		//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++

				$(".TaxonomiesF").each(function(){
   					$(this).ready(function(){	

   						$(this).closest(":has(.h .Terms .termsF)").find(".termsF").attr("name","' . $field['name'] . '[" + arr[$(this).closest(":has(.h .Taxonomies .TaxonomiesF)").find(".TaxonomiesF").val()][0][2]+ "]")

   						$(this).closest(":has(.h .Terms .termsF)").find(".termsF").select2({


							multiple: true,
					     	query: function (query) {

					     		   var data = {results: []}, i;
					
					     		   for (i in arr[$(this).closest(":has(.h .Taxonomies .TaxonomiesF)").find(".TaxonomiesF").val()] ) { 
					     		   		data.results.push({id: arr[$(this).closest(":has(.h .Taxonomies .TaxonomiesF)").find(".TaxonomiesF").val()][i][1] , text: arr[$(this).closest(":has(.h .Taxonomies .TaxonomiesF)").find(".TaxonomiesF").val()][i][0]});
					     		   }
					     		   query.callback(data);
 					    	},
 					    	initSelection : function (element, callback) {

    			   		var elementText = $(element).val();

    			        var data = {id: elementText, text: elementText};
    			        callback(data);
    			    	}
					    });
				    });				
   				});

		//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++

				})(jQuery);
			</script> ';
        }
    }
示例#10
0
 function render_location_value($options)
 {
     // vars
     $options = wp_parse_args($options, array('group_id' => 0, 'rule_id' => 0, 'value' => null, 'param' => null));
     // vars
     $choices = array();
     // some case's have the same outcome
     if ($options['param'] == "page_parent") {
         $options['param'] = "page";
     }
     switch ($options['param']) {
         /*
          *  Post
          */
         case "post_type":
             // get post types
             $post_types = acf_get_post_types(array('show_ui' => 1, 'exclude' => array('attachment')));
             // get choices
             $choices = acf_get_pretty_post_types($post_types);
             // end
             break;
         case "post":
             // get post types
             $post_types = acf_get_post_types(array('exclude' => array('page', 'attachment')));
             // get posts grouped by post type
             $groups = acf_get_grouped_posts(array('post_type' => $post_types));
             if (!empty($groups)) {
                 foreach (array_keys($groups) as $group_title) {
                     // vars
                     $posts = acf_extract_var($groups, $group_title);
                     // override post data
                     foreach (array_keys($posts) as $post_id) {
                         // update
                         $posts[$post_id] = acf_get_post_title($posts[$post_id]);
                     }
                     // append to $choices
                     $choices[$group_title] = $posts;
                 }
             }
             break;
         case "post_template":
             // vars
             $templates = wp_get_theme()->get_post_templates();
             $default = apply_filters('default_page_template_title', __('Default Template', 'acf'));
             // choices
             $choices = array('default' => $default);
             // templates
             if (!empty($templates)) {
                 foreach ($templates as $post_type => $post_type_templates) {
                     $choices = array_merge($choices, $post_type_templates);
                 }
             }
             // break
             break;
         case "post_category":
             $terms = acf_get_taxonomy_terms('category');
             if (!empty($terms)) {
                 $choices = array_pop($terms);
             }
             break;
         case "post_format":
             $choices = get_post_format_strings();
             break;
         case "post_status":
             global $wp_post_statuses;
             if (!empty($wp_post_statuses)) {
                 foreach ($wp_post_statuses as $status) {
                     $choices[$status->name] = $status->label;
                 }
             }
             break;
         case "post_taxonomy":
             $choices = acf_get_taxonomy_terms();
             // unset post_format
             if (isset($choices['post_format'])) {
                 unset($choices['post_format']);
             }
             break;
             /*
              *  Page
              */
         /*
          *  Page
          */
         case "page":
             // get posts grouped by post type
             $groups = acf_get_grouped_posts(array('post_type' => 'page'));
             if (!empty($groups)) {
                 foreach (array_keys($groups) as $group_title) {
                     // vars
                     $posts = acf_extract_var($groups, $group_title);
                     // override post data
                     foreach (array_keys($posts) as $post_id) {
                         // update
                         $posts[$post_id] = acf_get_post_title($posts[$post_id]);
                     }
                     // append to $choices
                     $choices = $posts;
                 }
             }
             break;
         case "page_type":
             $choices = array('front_page' => __("Front Page", 'acf'), 'posts_page' => __("Posts Page", 'acf'), 'top_level' => __("Top Level Page (no parent)", 'acf'), 'parent' => __("Parent Page (has children)", 'acf'), 'child' => __("Child Page (has parent)", 'acf'));
             break;
         case "page_parent":
             // refer to "page"
             break;
         case "page_template":
             // vars
             $templates = wp_get_theme()->get_page_templates();
             $default = apply_filters('default_page_template_title', __('Default Template', 'acf'));
             // merge
             $choices = array_merge(array('default' => $default), $templates);
             break;
             /*
              *  User
              */
         /*
          *  User
          */
         case "current_user":
             // viewing
             $choices = array('logged_in' => __('Logged in', 'acf'), 'viewing_front' => __('Viewing front end', 'acf'), 'viewing_back' => __('Viewing back end', 'acf'));
             break;
         case "current_user_role":
             // global
             global $wp_roles;
             // specific roles
             $choices = $wp_roles->get_names();
             // multi-site
             if (is_multisite()) {
                 $choices = array_merge(array('super_admin' => __('Super Admin', 'acf')), $choices);
             }
             break;
         case "user_role":
             global $wp_roles;
             $choices = array_merge(array('all' => __('All', 'acf')), $wp_roles->get_names());
             break;
         case "user_form":
             $choices = array('all' => __('All', 'acf'), 'edit' => __('Add / Edit', 'acf'), 'register' => __('Register', 'acf'));
             break;
             /*
              *  Forms
              */
         /*
          *  Forms
          */
         case "attachment":
             $choices = array('all' => __('All', 'acf'));
             break;
         case "taxonomy":
             $choices = array_merge(array('all' => __('All', 'acf')), acf_get_taxonomies());
             // unset post_format
             if (isset($choices['post_format'])) {
                 unset($choices['post_format']);
             }
             break;
         case "comment":
             // vars
             $choices = array('all' => __('All', 'acf'));
             // append post types
             $choices = array_merge($choices, acf_get_pretty_post_types());
             // end
             break;
         case "widget":
             global $wp_widget_factory;
             $choices = array('all' => __('All', 'acf'));
             if (!empty($wp_widget_factory->widgets)) {
                 foreach ($wp_widget_factory->widgets as $widget) {
                     $choices[$widget->id_base] = $widget->name;
                 }
             }
             break;
     }
     // allow custom location rules
     $choices = apply_filters('acf/location/rule_values/' . $options['param'], $choices);
     // create field
     acf_render_field(array('type' => 'select', 'prefix' => "acf_field_group[location][{$options['group_id']}][{$options['rule_id']}]", 'name' => 'value', 'value' => $options['value'], 'choices' => $choices));
 }
 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" : "");
                 $choices[] = $k;
             }
         }
     }
     // null
     if ($field['allow_null']) {
         array_unshift($els, array('type' => 'option', 'value' => '', 'label' => '- ' . $field['placeholder'] . ' -'));
     }
     // html
     echo '<select ' . acf_esc_attr($atts) . '>';
     // construct html
     if (!empty($els)) {
         foreach ($els as $el) {
             // extract type
             $type = acf_extract_var($el, 'type');
             if ($type == 'option') {
                 // get label
                 $label = acf_extract_var($el, 'label');
                 // validate selected
                 if (acf_extract_var($el, 'selected')) {
                     $el['selected'] = 'selected';
                 }
                 echo acf_esc_attr($el);
                 echo '<option ' . acf_esc_attr($el) . '>' . $label . '</option>';
             } else {
                 echo '<' . $type . ' ' . acf_esc_attr($el) . '>';
             }
         }
     }
     echo '</select>';
 }
示例#12
0
 function render_field_settings($field)
 {
     // default_value
     acf_render_field_setting($field, array('label' => __('Filter by Post Type', 'acf'), 'instructions' => '', 'type' => 'select', 'name' => 'post_type', 'choices' => acf_get_pretty_post_types(), 'multiple' => 1, 'ui' => 1, 'allow_null' => 1, 'placeholder' => __("All post types", 'acf')));
     // default_value
     acf_render_field_setting($field, array('label' => __('Filter by Taxonomy', 'acf'), 'instructions' => '', 'type' => 'select', 'name' => 'taxonomy', 'choices' => acf_get_taxonomy_terms(), 'multiple' => 1, 'ui' => 1, 'allow_null' => 1, 'placeholder' => __("All taxonomies", 'acf')));
     // allow_null
     acf_render_field_setting($field, array('label' => __('Allow Null?', 'acf'), 'instructions' => '', 'name' => 'allow_null', 'type' => 'true_false', 'ui' => 1));
     // multiple
     acf_render_field_setting($field, array('label' => __('Select multiple values?', 'acf'), 'instructions' => '', 'name' => 'multiple', 'type' => 'true_false', 'ui' => 1));
     // return_format
     acf_render_field_setting($field, array('label' => __('Return Format', 'acf'), 'instructions' => '', 'type' => 'radio', 'name' => 'return_format', 'choices' => array('object' => __("Post Object", 'acf'), 'id' => __("Post ID", 'acf')), 'layout' => 'horizontal'));
 }