Well, may you're over complicating things.
Beside the fact i should run the query that we assume is correct, where you want to display the result?
In WordPress? Because the code you present is may suitable to run into phpBB side, not wordpress.
The query use variables and the way/style phpBB do things, not the wordpress way that basically is based into ezSQL library style.
a query into wp_w3all plugin, that since i use ezSQL even before WP, i use with old wild style, and not this
https://developer.wordpress.org/referen ... b/prepare/
that over complicate things for me, i know that not secure values needs to be passed on queries wrapped like this:
$w3db_conn->get_results(" SELECT * FROM topics where aVal = ' ".$var." ' ");
substantially wrapping/casting $vars like this
' " . $var . " ' (i give a white space to make it more clear the way it need to be)
and not this way:
$w3db_conn->get_results("SELECT * FROM topics where aVal = $var");
and not like this:
$w3db_conn->get_results("SELECT * FROM topics where aVal = ".$var.");
if you're not secure of what data are coming in. And i normally by the way like to know (sanitize) everything is coming in.
So a query in wp is more easy then in phpBB, like this (look that $w3all_config["table_prefix"] can be a more easy named var or even not a var so all result even much more readable):
Code: Select all
$topics = $w3db_conn->get_results("SELECT T.*, P.*, U.*
FROM ".$w3all_config["table_prefix"]."topics AS T
JOIN ".$w3all_config["table_prefix"]."posts AS P on (T.topic_last_post_id = P.post_id and T.forum_id = P.forum_id)
JOIN ".$w3all_config["table_prefix"]."users AS U on U.user_id = T.topic_last_poster_id
WHERE T.topic_visibility = 1
AND T.forum_id IN(".$gf.")
AND P.post_visibility = 1
ORDER BY T.topic_last_post_time DESC
LIMIT 0,$ntopics");
do you want to move the code above into wordpress? How the shortcode or widget should be named?