This question already has an answer here:
I know, this question was asked before several times, but I didn't find the answer suitable for my task. I asked the same question on StackOverflow already, but, I guess, this community is more attuned to WordPress related questions.
I want to search in forum for the same keyword and then simply add results to existing WP search results array. In Joomla there's an event for it, which allows you to add custom searches by plugins. Only when all plugins were fired, pagination is calculated. WordPress seems to work in a very different way and it confusing me right now.
The main condition: it MUST work on main search.php, so custom search pages are not a solution.
I've added pre_get_posts hook to my plugin and queried forum by the same keyword. Then adjusted the look of forum results with the_permalink, author_link, the_author, the_category hooks. I even changed the number of posts found and pagination now shows proper number pf pages. No problem with that.
What I have problem with, is pagination behavior and querying of forum, when WordPress has no more posts matching criteria.
Long story short, forum results should be added to WP results and, ideally, sorted by given criteria (title, date, etc.).
Can anybody give me an example on where and when should I add my results properly? Honestly, I'm a little lost here.
A little update...
Joomla has a very simple algorithm in processing results from different plugins (queries). First it queries its own database, then calls all search related plugins and passes them current array of results. Each plugin simply pushes its own results to this array. And only then pagination is calculated. Easy-peasy.
Basically, I need the same: somehow push the results from forum to WP results array and make pagination work. I don't want forum to be searched from some widget and results displayed on other search page. This I know how to achieve.