There are view issues with the query:
- First what the @janh wrote.
- Second why you removing the am/pm when
you could easily use thedate("Y-m-d H:i:s");
- Third, there is this
little helper for the database table prefixes$wpdb->prefix
- Users table the column name is
display_name
- Also when you make aliases is a good rule to stick with them through the query even if there are not multiple columns with the same name.
For example without counting the bp_xprofile_data
table that I mocked:
$reply_id = $_REQUEST["id"];
$postId = $_REQUEST["post_id"];
$data = date("Y-m-d H:i:s");
$mysqli_query = "SELECT p.ID, COALESCE(w.value,a.display_name) value, p.post_title, p.post_date, p.post_content, p.post_author, a.user_login ";
$mysqli_query .= " FROM {$wpdb->prefix}posts p ";
$mysqli_query .= " INNER JOIN {$wpdb->prefix}users a ON a.ID = p.post_author ";
$mysqli_query .= " LEFT JOIN {$wpdb->prefix}bp_xprofile_data w ON w.user_id = a.ID ";
$mysqli_query .= " WHERE p.post_type="reply" ";
$mysqli_query .= " AND p.post_parent = %d ";
$mysqli_query .= " AND p.ID > %d ";
$mysqli_query .= " AND TIMEDIFF( %s, p.post_date ) < '00:00:15' ";
$mysqli_query .= " AND p.post_content IS NOT NULL ";
$mysqli_query .= " ORDER BY p.post_date ASC ";
$mysqli_query .= " LIMIT 0 , 5";
$reply_query = $wpdb->prepare($mysqli_query, $postId, $reply_id, $data);
$results = $wpdb->get_results( $reply_query );