C
C
Chokatillo2017-03-26 18:26:28
MySQL
Chokatillo, 2017-03-26 18:26:28

How to create sql query in wordpress

The WP-Recall
plugin works for me. The plugin displays its chat (comments) for posts with the following code:

<?php global $post; echo do_shortcode('[rcl-chat chat_room="post-'.$post->ID.'" userslist="1"]'); ?>

I need to display the last one message in this chat, but the chat cannot do this.
They told me that I can do this using an sql query, namely:
Pure sql query to get the last message of a particular chat is as follows:
SELECT * FROM `wp_rcl_chat_messages` AS t_mess
LEFT JOIN `wp_rcl_chats` AS t_chat
ON t_chat.chat_id = t_mess.chat_id
WHERE t_chat.chat_room = 'fchat'
ORDER BY t_mess.message_id DESC
LIMIT 1

where t_chat.chat_room = 'fchat' - instead of fchat, insert your chat ID.
Vooot ... but I don’t understand how it fumbles at all, but I’m trying to create an sql query in the WordPress function like this:
global $wpdb;
$wpdb->query("
SELECT * FROM `wp_rcl_chat_messages` AS t_mess
LEFT JOIN `wp_rcl_chats` AS t_chat
ON t_chat.chat_id = t_mess.chat_id
WHERE t_chat.chat_room = '.$post->ID.'
ORDER BY t_mess.message_id DESC
LIMIT 1
");

But the pancake doesn't make a fuss. I don't understand.
Tell me, pliz, who can do it .
Thank you for your attention!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Pushkarev, 2017-03-26
@AXP-dev

$wpdb->query
Alternatively $wpdb->get_results

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question