Support

Account

Home Forums Feature Requests Add filter to taxonomy field AJAX response

Solving

Add filter to taxonomy field AJAX response

  • Hello,

    I need to disable terms of a taxonomy field based on a certain business logic. Security at this point is not a concern, so HTML’s “disabled” is sufficient. In order to achieve this, Select2 provides a “disabled” property.

    If I do something like that in advanced-custom-fields-pro/includes/fields/class-acf-field-taxonomy.php get_ajax_query(), terms, indeed, are disabled. (Of course I don’t want to alter the original ACF file and these disabled-states have to follow another business logic. This is just for clarification.)

    
    /// append to r
    		foreach( $terms as $term ) {
    
    			// add to json
    			$results[] = array(
    				'id'	=> $term->term_id,
    				'text'	=> $this->get_term_title( $term, $field, $options['post_id'] ),
    				'disabled' => true // for demonstration purposes
    			);
    
    		}
    

    The only thing that hinders me to modify this ajax response is that response does not pass a WordPress filter. Hence, I’d kindly ask you to do this slight modification to your code to achieve this:

    
    // vars
    		$response = array(
    			'results'	=> $results,
    			'limit'		=> $limit
    		);
    
    		// PLEASE ADD THESE FEW LINES:
    		// filter to enable 3rd party modifications
    		$response = apply_filters('acf/fields/taxonomy/ajax-response', $response, $field);
    		$response = apply_filters('acf/fields/taxonomy/ajax-response/name=' . $field['name'], $response, $field);
    		$response = apply_filters('acf/fields/taxonomy/ajax-response/key=' . $field['key'], $response, $field);
    
    		// return
    		return $response;
    

    Thank you!

  • This reply has been marked as private.
Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.

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 Cookie Policy. If you continue to use this site, you consent to our use of cookies.