Support

Account

Home Forums General Issues Hide values that have been selected in other post Reply To: Hide values that have been selected in other post

  • Hi there!

    If I understand correctly, you want to filter all tracks that have a certain condition already defined on the select.

    I did something similar using: acf/fields/post_object/query (https://www.advancedcustomfields.com/resources/acf-fields-post_object-query/).

    You need to a filter that will call the function that will narrow down the choices using a query.

    In my case (this is OOP code but you should get the gist), I added the filter:

    $action_filter_register->add_filter( 'acf/fields/post_object/query/name=client_match_object_field', Match::class, 'filter_participant_options', 10, 3 );

    And then defined the function that did the trick:

    	public function filter_participant_options( $args, $field, $post_id ) {
    		$allowed_states = EntityStates::get_allowed_states_for_matching();
    		$args['numberposts'] = -1;
    		$args['meta_query']  = array(
    			array(
    				'key'     => '_state',
    				'value'   => implode( ',', array_keys( $allowed_states ) ),
    				'compare' => 'IN',
    			),
    		);
    		return $args;
    	}

    Hope this helps!