Search for messages by username

Home Forums Front End PM PRO Search for messages by username

This topic is: Not Resolved
Viewing 9 posts - 1 through 9 (of 9 total)
  • Author
  • #20706
    Dawson College


    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.


    When searching messages it search in message subject and content.

    Dawson College
    This reply has been marked as private.

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

    Dawson College

    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;

    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

    Raeanna Lewarne

    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?


    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.

    Al Nawras

    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 create topic in this support forum.

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