Search for messages by username


Home Forums Front End PM PRO Search for messages by username

This topic is: Not Resolved

This topic contains 8 replies, has 4 voices, and was last updated by  Al Nawras 4 days, 3 hours ago.

Viewing 9 posts - 1 through 9 (of 9 total)
  • Author
    Posts
  • #20706

    Dawson College
    Participant

    Hi,

    When I try to search for a message by username I’m getting “No messages found. Try different filter.”

    Is it possible to search by any of the user fields that contain the user login name.

    #20716

    shamim
    Keymaster

    When searching messages it search in message subject and content.

    #20718

    Dawson College
    Participant
    This reply has been marked as private.
    #20721

    shamim
    Keymaster

    Possible but you will need to write complex query for this.

    #20746

    Dawson College
    Participant

    Hey Shamim,

    What are your thoughts on this? This seems to get the job done.

    
       add_filter( 'fep_filter_message_query_sql', 'fep_filter_message_query_sql', 10, 2 );
    
       /**
         * Allows for the searching of student number on the message list page
         *
         * @param $sql
         * @param $class
         * @return mixed
         */
        function fep_filter_message_query_sql( $sql, $class ) {
    
            if( isset( $_GET['fep-search'] ) && ! empty( $_GET['fep-search'] ) &&
                preg_match( '/^\d{7}$/', trim( strtolower( $_GET['fep-search'] ) ) )
            ) {
    
                    global $wpdb;
    
                    // Inject DISTINCT cause the join seems to bring duplicate records
                    $sql = str_replace( 'SELECT ', 'SELECT DISTINCT ', $sql );
    
                    // Inject the users table join
                    $sql = str_replace( ' WHERE', ' INNER JOIN ' . $wpdb->users . ' on adm_fep_messages.mgs_author = ' . $wpdb->users . '.ID WHERE', $sql );
    
                    // Inject for the where on user_login = ?
                    $sql = str_replace( ' ORDER BY',' OR ( ' . $wpdb->users . '.user_login = "' . esc_sql( trim( strtolower( $_GET[ 'fep-search' ] ) ) ) . '") ORDER BY', $sql );
            }
    
            return $sql;
        }
    
    #20749

    shamim
    Keymaster

    Yes it will work, but search only for message sender, message recipients will not be searched.
    Some observation
    1. Missing space before INNER JOIN
    2. use esc_sql instead of esc_html or use $wpdb->prepare

    #21627

    Raeanna Lewarne
    Participant

    I am attempting to achieve this same functionality. Ultimately I want to open the messagebox>inbox with only messages from a specified user (and to the current user). Is this possible?

    #21687

    shamim
    Keymaster

    Yes possible. But you will need to write some custom php code.
    Do you have basic knowledge in php? I can instruct you.

    Also it is preferred to create a new topic for each question. That way we better support.

    #23336

    Al Nawras
    Participant

    How to accomplish a search for a message by username?

Viewing 9 posts - 1 through 9 (of 9 total)

You need to purchase ‘Front End PM PRO’ to reply in this support forum.

If you already purchased ‘Front End PM PRO’ please LOGIN.