Home Forums Feature Requests Add filter to taxonomy field AJAX response


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
    		// 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)

The topic ‘Add filter to taxonomy field AJAX response’ is closed to new replies.