• Resolved ljkeashly

    (@ljkeashly)


    Hi,

    I have a field called Paper Mail which is a check box. I would like to have a page that displays only members that have the check box checked. Is there a way to display only the members that have the checked box rather than all members sorted my the Paper Mail field?

Viewing 15 replies - 1 through 15 (of 26 total)
  • @ljkeashly

    Your issue is similar to “Display Profiles with Today’s Birthday”
    which is an example of Directory usage in this UM Guide:

    https://docs.ultimatemember.com/article/1746-display-profiles-with-upcoming-recent-and-todays-birthdays

    Thread Starter ljkeashly

    (@ljkeashly)

    Hi,

    Thank you for your response. But this doesn’t seem to be limiting the users for me.

    My meta key is snail_mail and has 1 Edit Choices of Yes.

    So I changed your code to:

    add_action(‘um_user_before_query’,’pp_show_snail_mail’, 10, 2);
    function pp_show_snail_mail( $query_args, $obj ){

     $directory_id = $directory_data['form_id'];
    
    if( 765 !== $directory_id ) return $query_args;
    
    $query_args['meta_query'][ ] = array(
            'key' => 'snail_mail',
            'value' => 'Yes',
            'compare' => 'RLIKE'
    );
    
    $query_args['orderby'] = array(
        'lot' => 'ASC',
    ); 
    
    return $query_args;

    }

    the new member directory I made for this is 765.

    When I display this new member directory it is showing my all member and the ones that have snail mail enabled are showing Yes under the Display name in the tagline area.

    Any ideas as to what is wrong with my function?

    Thanks again for your help.

    @ljkeashly

    Try to use this search code with double quotes inside the singles with LIKE

            'value' => '"Yes"',
            'compare' => 'LIKE'
    • This reply was modified 10 months, 3 weeks ago by missveronica.
    • This reply was modified 10 months, 3 weeks ago by missveronica.
    Thread Starter ljkeashly

    (@ljkeashly)

    Thank you for your suggestion. I made the change but nothing changed, still getting all members showing up.

    I have triple checked and the meta key is snail_mail. There are only 4 members that have that field checked. The database shows:

    snail_mail a:1:{i:0;s:3:"Yes";}

    for checked users and

    snail_mail a:0:{}

    for unchecked users.

    Should I maybe be using 1 as the value rather than Yes?

    Thanks for your help, much appreciated.

    @ljkeashly

    Verify that the Directory ID is right with the value 765.

    Thread Starter ljkeashly

    (@ljkeashly)

    Yes, the Directory ID is correct. This is the shortcode for it: [ultimatemember form_id=”765″]

    @ljkeashly

    How did you install the code snippet?

    Either to your active theme’s functions.php file
    or the “Code Snippets” Plugin

    https://wordpress.org/plugins/code-snippets/

    Thread Starter ljkeashly

    (@ljkeashly)

    I added it to my theme’s functions.php file.

    @ljkeashly

    If you are using UM Settings -> Advanced -> Features – “Custom usermeta table”
    the UM Filter hook in the code snippet is not supported by UM
    but works OK with the default usermeta table.

    Thread Starter ljkeashly

    (@ljkeashly)

    Hi,

    Yes, Enable custom table for usermeta is checked.

    So, is there a way to do this with the custom usermeta table?

    Thank you for your help,

    @ljkeashly

    No, I don’t have a code snippet for the custom usermeta table.
    Have you tried “Admin filtering” of your snail_mail field in the Directory setup?

    Thread Starter ljkeashly

    (@ljkeashly)

    Hi,

    The Admin filtering doesn’t let you specify a value for the field you choose. And since all users have the Paper Mail field they all show not just the ones with the field set to Yes.

    @ljkeashly

    You can try this code snippet prepared with your settings
    for the UM “custom usermeta table”.

    add_action( 'um_pre_users_query', 'um_pre_users_query_field_set', 10, 3 );
    function um_pre_users_query_field_set( $obj, $directory_data, $sortby ) {
        global $wpdb;
        $form_id    = 765;
        $meta_key   = 'snail_mail';
        $meta_value = 'a:1:{i:0;s:3:\"Yes\";}';
        $sortby     = 'lot';
        if ( isset( $directory_data['form_id'] ) && $directory_data['form_id'] == $form_id ) {
            $obj->where_clauses   = array();
            $obj->where_clauses[] = "( umm_general.um_key = '{$meta_key}' AND umm_general.um_value = '{$meta_value}' )";
            $obj->joins[]   = $wpdb->prepare( "LEFT JOIN {$wpdb->prefix}um_metadata umm_sort ON ( umm_sort.user_id = u.ID AND umm_sort.um_key = %s )", $sortby );
            $obj->sql_order = ' ORDER BY CAST( umm_sort.um_value AS CHAR ) ASC ';
        }
    }

    You install the code snippet by adding it
    to your active theme’s functions.php file
    or use the “Code Snippets” Plugin

    https://wordpress.org/plugins/code-snippets/

    Thread Starter ljkeashly

    (@ljkeashly)

    Hi,

    Thank you so much for writing that function. Unfortunately it did not work. Now I don’t get any users showing on the list.

    @ljkeashly

    I have triple checked and the meta key is snail_mail. There are only 4 members that have that field checked. The database shows:

    snail_mail a:1:{i:0;s:3:”Yes”;}

    Which table did you find a:1:{i:0;s:3:"Yes";}?

Viewing 15 replies - 1 through 15 (of 26 total)

The topic ‘Display on members with field set’ is closed to new replies.