Home › Forums › Front End PM PRO › Search for messages by username
Tagged: search, search by user
- This topic has 8 replies, 4 voices, and was last updated 6 years, 8 months ago by Al Nawras.
- AuthorPosts
- January 15, 2019 at 3:11 am #20706Dawson CollegeParticipant
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.
January 15, 2019 at 3:29 am #20716Shamim HasanKeymasterWhen searching messages it search in message subject and content.
January 15, 2019 at 3:32 am #20718Dawson CollegeParticipantThis reply has been marked as private.January 15, 2019 at 3:54 am #20721Shamim HasanKeymasterPossible but you will need to write complex query for this.
January 16, 2019 at 4:37 am #20746Dawson CollegeParticipantHey 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; }January 16, 2019 at 7:50 am #20749Shamim HasanKeymasterYes 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->prepareFebruary 14, 2019 at 10:12 pm #21627Raeanna LewarneParticipantI 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?
February 16, 2019 at 11:16 pm #21687Shamim HasanKeymasterYes 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.
April 15, 2019 at 6:12 pm #23336Al NawrasParticipantHow to accomplish a search for a message by username?
- AuthorPosts
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.