• Resolved mvereijken

    (@mvereijken)


    To link each user profile to a country and city, I used the choices callback based on this guide: https://docs.ultimatemember.com/article/1539-choices-callback-feature-in-um-2-1

    I would now like to use these fields to create member directories that contain profiles of specific cities. I manage to set admin filtering that ensures only profiles linked to a specific country are shown, but as soon as I try to assign a specific city, the dropdown remains empty.

    It seems that the PHP function that handles the dynamic filling of the dropdown options does not work here. Could you solve this? I need this ASAP so would love to hear from you soon.

    Thanks in advance!

Viewing 8 replies - 1 through 8 (of 8 total)
  • @mvereijken

    Make a User Registration with Home City Amsterdam and you can select Amsterdam in the City dropdown. The City dropdown is based on actaul Registrations in your DB.

    Thread Starter mvereijken

    (@mvereijken)

    @missveronicatv

    Do you mean that only options are shown that have results?

    I don’t think this is the problem as it works correctly in the frontend filters and when registering. In addition, there are various accounts that are linked to, for example, Amsterdam

    Thread Starter mvereijken

    (@mvereijken)

    Update: It seems that disabling setting ‘parent option’ in the city custom field fixes the problems. Is there a downside to deactivating this setting?

    Thread Starter mvereijken

    (@mvereijken)

    Unfortunately, this causes the filter options to no longer work properly. All cities are now shown instead of the cities within the selected country. I have tried to convert the PHP function in such a way that all cities are always shown within WP-admin, but unfortunately without success. Could a plugin maker advise me on how to fix this?

    @mvereijken

    What meta_key name are you using for the country names?

    Thread Starter mvereijken

    (@mvereijken)

    @missveronicatv the meta_key I use: location_country

    Plugin Support andrewshu

    (@andrewshu)

    Hello @mvereijken

    Sorry for the late answer. Try to add this hook (please change the metakey here to your city metakey – ‘location_city’ === $attrs[‘metakey’] ):

    add_filter( 'um_member_directory_filter_select_options_sorted', 'custom_um_member_directory_filter_select_options_sorted', 10, 2 );
    function custom_um_member_directory_filter_select_options_sorted( $options, $attrs ){
        if ( 'location_city' === $attrs['metakey'] ){
    	    if ( ! empty( $attrs['custom_dropdown_options_source'] ) && ! empty( $attrs['parent_dropdown_relationship'] ) ) {
                global $wpdb;
    		    $values_array = $wpdb->get_col(
    			    $wpdb->prepare(
    				    "SELECT DISTINCT meta_value
    								FROM $wpdb->usermeta
    								WHERE meta_key = %s AND
    									  meta_value != ''",
    				    $attrs['metakey']
    			    )
    		    );
    
    		    if ( ! empty( $values_array ) && in_array( $attrs['type'], array( 'select', 'multiselect', 'checkbox', 'radio' ) ) ) {
    			    $values_array = array_map( 'maybe_unserialize', $values_array );
    			    $temp_values = array();
    			    foreach ( $values_array as $values ) {
    				    if ( is_array( $values ) ) {
    					    $temp_values = array_merge( $temp_values, $values );
    				    } else {
    					    $temp_values[] = $values;
    				    }
    			    }
    
    			    $values_array = array_unique( $temp_values );
    		    }
    
    		    $options = UM()->fields()->get_options_from_callback( $attrs, $attrs['type'] );
    		    $options = array_intersect_key( array_map( 'trim', $options ), array_flip( $values_array ) );
    	    }
        }
    
        return $options;
    }
    

    Regards.

    Plugin Support andrewshu

    (@andrewshu)

    Hi @mvereijken

    This thread has been inactive for a while so we’re going to go ahead and mark it Resolved.

    Please feel free to re-open this thread if any other questions come up and we’d be happy to help. ??

    Regards

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Bug: Member directory admin filtering not possible with choices callback feature’ is closed to new replies.