Integrate forum search into theme search
Quote from underscore on July 24, 2019, 11:35 amI have copied my themes search.php into the child directory and inserted
if (is_user_logged_in()) { echo "results of forum search"; }but I am not sure how to get the results also from
wp-content/plugins/asgaros-forum/includes/forum-search.phpthank you.
I have copied my themes search.php into the child directory and inserted
if (is_user_logged_in()) { echo "results of forum search"; }
but I am not sure how to get the results also from
wp-content/plugins/asgaros-forum/includes/forum-search.php
thank you.
Quote from Asgaros on July 24, 2019, 3:09 pmHello @underscore
When I developed the search-functionality I planned to integrate search-results directly into the WordPress Core search functionality. The problem why I implemented my own search-engine at the end was the lack of an official search API which can be used to search content inside custom tables. Of course it would be possible to add the results to the core which some hardcoded query-modifications via filters and hooks. You can find an example in the old ticket here:
https://github.com/Asgaros/asgaros-forum/issues/7
But this would lead to a lot of problems, for example possible incompatibilities with other plugins and the risk, that after an update of WordPress the search-functionality would not work anymore. As long as there is not a good way for this issue provided by the WordPress-developers its almost impossible to integrate this in a safe way.
Hello @underscore
When I developed the search-functionality I planned to integrate search-results directly into the WordPress Core search functionality. The problem why I implemented my own search-engine at the end was the lack of an official search API which can be used to search content inside custom tables. Of course it would be possible to add the results to the core which some hardcoded query-modifications via filters and hooks. You can find an example in the old ticket here:
https://github.com/Asgaros/asgaros-forum/issues/7
But this would lead to a lot of problems, for example possible incompatibilities with other plugins and the risk, that after an update of WordPress the search-functionality would not work anymore. As long as there is not a good way for this issue provided by the WordPress-developers its almost impossible to integrate this in a safe way.
Quote from underscore on July 24, 2019, 4:06 pmFully agree – integrating into core isn’t a good idea. I just wanted some quick fix for my child themes’ search.php.
Cut & paste of https://github.com/Asgaros/asgaros-forum/issues/7 did not work as all functions are already declared (I did not see any API action or hook related to the forum search?).
Also the table structure changed considerably.
Fully agree – integrating into core isn’t a good idea. I just wanted some quick fix for my child themes’ search.php.
Cut & paste of https://github.com/Asgaros/asgaros-forum/issues/7 did not work as all functions are already declared (I did not see any API action or hook related to the forum search?).
Also the table structure changed considerably.
Quote from underscore on July 26, 2019, 9:50 amRewrote the SQL in https://github.com/Asgaros/asgaros-forum/issues/7 to
$mysqli = mysqli_connect($host_name, $user_name, $password, $database); $mysqli -> query("SET NAMES 'utf8'"); $q = get_search_query(); $sql = "SELECT author_id, date_edit, text, forum_topics.slug AS slug, wp_users.user_nicename AS name FROM forum_posts LEFT JOIN forum_topics ON forum_posts.parent_id = forum_topics.id LEFT JOIN wp_users ON forum_posts.author_id = wp_users.ID WHERE text LIKE '%$q%';"; $res = mysqli_query($mysqli,$sql); while ($row = mysqli_fetch_assoc($res)) { $dt = date("M d, Y", strtotime($row["date_edit"])); $nm = $row["name"]; # ... # theme search output block # ... }and are updating the theme search output block in the loop.
Rewrote the SQL in https://github.com/Asgaros/asgaros-forum/issues/7 to
$mysqli = mysqli_connect($host_name, $user_name, $password, $database); $mysqli -> query("SET NAMES 'utf8'"); $q = get_search_query(); $sql = "SELECT author_id, date_edit, text, forum_topics.slug AS slug, wp_users.user_nicename AS name FROM forum_posts LEFT JOIN forum_topics ON forum_posts.parent_id = forum_topics.id LEFT JOIN wp_users ON forum_posts.author_id = wp_users.ID WHERE text LIKE '%$q%';"; $res = mysqli_query($mysqli,$sql); while ($row = mysqli_fetch_assoc($res)) { $dt = date("M d, Y", strtotime($row["date_edit"])); $nm = $row["name"]; # ... # theme search output block # ... }
and are updating the theme search output block in the loop.
Quote from Asgaros on July 26, 2019, 10:35 amHello @underscore
I dont think you need to establish an additional connection to the database-server there. Instead you can use the following WordPress function:
global $wpdb; $results = $wpdb->get_results("YOUR QUERY"); if (!empty($results)) { foreach ($results as $result) { // Do the output } }
Hello @underscore
I dont think you need to establish an additional connection to the database-server there. Instead you can use the following WordPress function:
global $wpdb; $results = $wpdb->get_results("YOUR QUERY"); if (!empty($results)) { foreach ($results as $result) { // Do the output } }
Quote from underscore on July 26, 2019, 11:27 amthank you – I am not so much in wp – will rewrite.
thank you – I am not so much in wp – will rewrite.
Quote from ve3meo on October 14, 2020, 5:36 amDo I understand this correctly to be a way for the Search on the WP site to return results from the Forum?
Does it work?
Do I understand this correctly to be a way for the Search on the WP site to return results from the Forum?
Does it work?