Support

Account

Home Forums Feedback Taxonomy labels and create/save tax modal

Solving

Taxonomy labels and create/save tax modal

  • Hi Guys,

    I apologize already for this ticket since this is both feedback and an issue for me that i’m trying to resolve.

    Currently i’m trying to create/modify the behavior of the taxonomy field from ACF.

    The taxonomy is called “make”.

    Field 1: Taxonomy depth 0 (make).
    Field 2: Is children (model).

    So i’m walking into a couple of issues here and some are bigger then others.

    1) How do i change/remove the child prefix “- ” and “– ” from the options label.
    [url=https://ibb.co/8bxmD79][img]https://i.ibb.co/FXYhbDz/acf1.png[/img][/url]
    2) I have the option enabled that let users create/save new terms from the edit/post screen. The issue here is that the tooltip/modal header references to the word “make” from the “taxonomy”. In my opinion it would have been better if this is taken from the fields label. Is there a way to modify this?
    2.1) It would be nice to be able to hide the parent selector on a field to field basis for cases like this where you implement parent and child fields/dropdowns (Taxonomy create/save terms option).

    I have seen a lot of people struggling creating setups like mine.

    Thanks,
    Patrick

  • 1) Screenshot issue 1.
    1
    2) Screenshot issue 2.
    2

  • Solved issue 1

    add_filter('acf/fields/taxonomy/result/key=field_605b7c5cc9dc9', 'my_acf_fields_taxonomy_result2', 10, 4);
    function my_acf_fields_taxonomy_result( $text, $term, $field, $post_id ) {
        $text = $term->name;
        return $text;
    }

    Feedback and issue 2 remains for the feature save/create terms.

    2.1) How to turn of the parent selector on specific field.
    2.2) Change the name of the tooltip/dialog(modal) with label name instead of the taxonomy.
    2.3) In the dialog(modal) replacing the label of parent with custom label name of a field to field basis.

    Ideally the should be some unique identification for the modals

  • As far as the popup goes, I can’t really help you. The modal foe adding a term is the modal built into WP. I have never found any information on how to change this.

    You could, in a round-a-bout way, alter the tooltip.

    1. Create a render field filter for the field that runs before the field is rendered
    2. In the render field filter above get the global $wp_taxonomies and alter $wp_taxonomies[$taxonomy]->labels->add_new_item to what you want it to say
    3. Create another render field filter that runs after the field is rendered to change the label back to what it should be.

    That being said, if I needed to build something like this for a client I would not be using a single taxonomy for make and model. Please bare with me because this is only where I would start and the details of getting it done would need to be figured out.

    First I would use two taxonomies, one for make and one for model. There would be a taxonomy field for the model term that allowed selecting the make term.

    I would filter the values shown in the model field based on the selection made in the make field. This may actually require not using taxonomy fields, but I don’t know this for sure. I would need to look at the ACF JS API documentation to see if the AJAX request on this field could be altered to include the value selected in make. The exact details of this research would make the decision on how to proceed.

    I would create my an acf/save_post action that would create the association between the model term and the make term when a new model term is added (basically look to see if the association already exists and if it does not then create it. Basically creating a parent/child association between these to taxonomies. Spitting the make and model taxonomies would also make it much easier to filter by these two fields and in the case of a model that is shared between 2 makes would mean that duplicate model entries would not be created.

    Assuming that the client also wanted urls like /product/make/$make/model/$model/ I would also add custom rewrite rules to accomplish this.

  • Hi John,

    Thanks for your extended feedback and your vision on the makes and models part. Basically this is already implemented as is as the case described above within a single taxonomy in a parent child construction.

    I managed to change the text for the tooltip and title from the popup thanks to your valuable feedback. Much appreciated, thanks!

    So i have only 1 thing to figure out and that is altering that parent selector field for the taxonomy.

    I have been digging true the fields file at “acf/includes/fields/class-acf-field-taxonomy”.

    So basically i need to be able to modify/extend the class “acf_field_taxonomy” / function “ajax_add_term” and change the behavior for field key X and Y.

    I will have some sleep and see if i can come to somekind of solution 😀

    if( is_taxonomy_hierarchical( $field['taxonomy'] ) ) {
    			
    			$choices = array();
    			$response = $this->get_ajax_query($args);
    			
    			if( $response ) {
    				
    				foreach( $response['results'] as $v ) { 
    					
    					$choices[ $v['id'] ] = $v['text'];
    					
    				}
    				
    			}
    			
    			acf_render_field_wrap(array(
    				'label'			=> __('Parent', 'acf'),
    				'name'			=> 'term_parent',
    				'type'			=> 'select',
    				'allow_null'	=> 1,
    				'ui'			=> 0,
    				'choices'		=> $choices
    			));
    			
    		}
Viewing 5 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic.