Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes for new functions, formatting/display errors, and error if no taxonomies were selected #2

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 37 additions & 38 deletions acf-multi-taxonomy-chooser-v5.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,53 +97,53 @@ function render_field_settings( $field ) {

// choices : Taxonomies
acf_render_field_setting( $field, array(
'label' => __('Choose Allowed Post Type','post_type_chooser'),
'label' => __('Choose Allowed Taxonomies','acf-multi-taxonomy-chooser'),
'instructions' => '',
'type' => 'select',
'name' => 'choices',
'choices' => acf_get_pretty_taxonomies(),
'multiple' => 1,
'ui' => 1,
'allow_null' => 1,
'placeholder' => __("All post types",'post_type_chooser'),
'placeholder' => __("All Taxonomies",'acf-multi-taxonomy-chooser'),
));


// multiple
acf_render_field_setting( $field, array(
'label' => __('Select multiple values?','post_type_chooser'),
'label' => __('Select multiple values?','acf-multi-taxonomy-chooser'),
'instructions' => '',
'type' => 'radio',
'name' => 'multiple',
'choices' => array(
1 => __("Yes",'post_type_chooser'),
0 => __("No",'post_type_chooser'),
1 => __("Yes",'acf-multi-taxonomy-chooser'),
0 => __("No",'acf-multi-taxonomy-chooser'),
),
'layout' => 'horizontal',
));

// id or slug
acf_render_field_setting( $field, array(
'label' => __('Return Value','post_type_chooser'),
'instructions' => __('Specify the returned value on front end','post_type_chooser'),
'label' => __('Return Value','acf-multi-taxonomy-chooser'),
'instructions' => __('Specify the returned value on front end','acf-multi-taxonomy-chooser'),
'type' => 'radio',
'name' => 'type_value',
'choices' => array(
1 => __("ID",'post_type_chooser'),
0 => __("Slug",'post_type_chooser'),
1 => __("ID",'acf-multi-taxonomy-chooser'),
0 => __("Slug",'acf-multi-taxonomy-chooser'),
),
'layout' => 'horizontal',
));

// multi or single
acf_render_field_setting( $field, array(
'label' => __('Return Value','post_type_chooser'),
'instructions' => __('Specify the returned value on front end','post_type_chooser'),
'label' => __('Return Value','acf-multi-taxonomy-chooser'),
'instructions' => __('Specify the returned value on front end','acf-multi-taxonomy-chooser'),
'type' => 'radio',
'name' => 'data_type',
'choices' => array(
1 => __("Multi",'post_type_chooser'),
0 => __("Single",'post_type_chooser'),
1 => __("Multi",'acf-multi-taxonomy-chooser'),
0 => __("Single",'acf-multi-taxonomy-chooser'),
),
'layout' => 'horizontal',
));
Expand Down Expand Up @@ -174,14 +174,14 @@ function render_field( $field ) {


$taxonomies = array();
$taxonomies = acf_force_type_array( $taxonomies );
$taxonomies = acf_get_array( $taxonomies );
$taxonomies = acf_get_pretty_taxonomies( $taxonomies );
$all_taxonomies = acf_get_taxonomy_terms();
$selected_taxonomies = array();
$terms = array();
$slug_name = $field['choices'];
$slug_name = ! empty( $field['choices'] ) ? $field['choices'] : array_keys( acf_get_pretty_taxonomies() );

foreach( $field['choices'] as $k1 => $v1 ) {
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 ) {
Expand Down Expand Up @@ -346,44 +346,43 @@ function render_field( $field ) {

}



// if ($field['data_type']) {

// html
echo '<select ' . acf_esc_attr( $atts ) . '>';

// construct html
if( !empty($els) ) {
// construct html
if( !empty($els) ) {

foreach( $els as $el ) {
foreach( $els as $el ) {

// extract type
$type = acf_extract_var($el, 'type');
// extract type
$type = acf_extract_var($el, 'type');


if( $type == 'option' ) {
if( $type == 'option' ) {

// get label
$label = acf_extract_var($el, 'label');
// get label
$label = acf_extract_var($el, 'label');


// validate selected
if( acf_extract_var($el, 'selected') ) {
// validate selected
if( acf_extract_var($el, 'selected') ) {

$el['selected'] = 'selected';
$el['selected'] = 'selected';

}
echo acf_esc_attr( $el );
echo '<option ' . acf_esc_attr( $el ) . '>' . $label . '</option>';
}
echo acf_esc_attr( $el );
echo '<option ' . acf_esc_attr( $el ) . '>' . $label . '</option>';

} else {
} else {

echo '<' . $type . ' ' . acf_esc_attr( $el ) . '>';
}
}
echo '<' . $type . ' ' . acf_esc_attr( $el ) . '>';
}
}

}
}

echo '</select>';
}
else {

Expand Down
4 changes: 2 additions & 2 deletions js/input.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

function initialize_field( $el ) {

$('.field_type-multi-taxonomy-chooser .select2-container-disabled').remove();
//$('.field_type-multi-taxonomy-chooser .select2-container-disabled').remove();

//$el.doStuff();

Expand All @@ -27,7 +27,7 @@

acf.add_action('ready append', function( $el ){

$("select.js-multi-taxonomy-select2").select2();
//$("select.js-multi-taxonomy-select2").select2();

// search $el for fields of type 'multi-taxonomy-chooser'
acf.get_fields({ type : 'multi-taxonomy-chooser'}, $el).each(function(){
Expand Down