Please or Register to create posts and topics.

Integrate forum search into theme search

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.

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.

If you want to support the development of Asgaros Forum, you can leave a good review or donate. Thank you very much!

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.

 

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.

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
    }
}

 

If you want to support the development of Asgaros Forum, you can leave a good review or donate. Thank you very much!

thank you – I am not so much in wp – will rewrite.

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?