Home › Forums › Feature Requests › Sort Taxonomy Field SOLVED
I love the Taxonomy field because it can be used to restrict how CMS users interact with complex Taxonomies.
However, it would be great to be able to order this from within ACF. Sort options could include Alpha order (default), Term ID, etc. This would really increase the usefulness of the Taxonomy field.
I actually patched the plugin to include this functionality.
At line 211, I added the following:
if($field['sort_order'] == 'alpha'){
$sort_args = array(
'orderby' => 'name',
'order' => 'ASC',
);
array_push($args, $sort_args);
}else if($field['sort_order'] == 'alpha_desc'){
$sort_args = array(
'orderby' => 'name',
'order' => 'DESC',
);
$args = array_merge($args, $sort_args);
}
And at approx line 384 (after the last ‘field_option’), I added:
<tr class="field_option field_option_<?php echo $this->name; ?>">
<td class="label">
<label><?php _e("Sort Order",'acf'); ?></label>
</td>
<td>
<?php
do_action('acf/create_field', array(
'type' => 'select',
'name' => 'fields['.$key.'][sort_order]',
'value' => $field['sort_order'],
'choices' => array(
'alpha' => __("Alpha Order Assending",'acf'),
'alpha_desc' => __("Alpha Order Desending",'acf'),
'id' => __("Term ID",'acf')
)
));
?>
</td>
</tr>
I’ve attached the PHP file (as a txt file) for those that would like to see it.
However, I can’t seem to get this to switch to an actual Select box. It seems to show a radio list regardless of specifying “Select”. Thoughts on that?
Hi @Quantum Dynamix
If you remove your custom ‘field_option’ code, does the field allow you to change the field_type setting?
Thanks
E
The topic ‘Sort Taxonomy Field SOLVED’ is closed to new replies.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.