Notifications
Clear all

[Solved] Integration with Search Analytics

5 Posts
2 Users
4 Likes
730 Views
Posts: 4
Topic starter
(@cornelraiu)
New Member
Joined: 3 years ago

Hello,

My name is Cornel and I am the developer of the Search Analytics plugin. 

I recently got a request from a user who asked me to integrate wpForo with my plugin. I was trying to do that, howerer, I came across one issue that prevents me from doing the integrations.

The way my plugin works is this: it captures a search string from the params and stores it in the database along with the number of results from the search and then it displays search statistics for the website. However, due to the way search is implemented in wpForo, I am not able to pull the search results count from the queries wpForo does without hook deep into the WP query filters.

I went through the plugin and it looks like the thing I need to be able to integrate it is the following:

In the file `class-posts.php` I would need an action like:

$sql = "SELECT COUNT(*) FROM ". $from ." ".implode(' ', $innerjoins);
if($wheres) $sql .= " WHERE " . implode( " AND ", $wheres );
$items_count = (int) WPF()->db->get_var($sql);

do_action( 'the_action_name', $items_count, $sql );


======= or, even better =======

if( $args['row_count'] ) $sql .= " LIMIT ". intval($args['offset']) ."," . intval($args['row_count']);

$posts = WPF()->db->get_results($sql, ARRAY_A);

do_action( 'the_action_name',
$items_count, $results, $sql );

This way I will be able to get the total posts resulting in the search with all the options from wpForo or just get the query and run it with small changes to accommodate the needs in the analytics system.

If this is not possible, I will hook into the `query` WordPress filter and get the query from there. But I'd prefer not to so because I don't want to run the query a second time.

Looking forward to your reply!

Thank you

4 Replies
Robert
Posts: 9966
Admin
(@robert)
Support Team
Joined: 7 years ago

Hi @cornelraiu,

Thank you for contacting us. We've just added an action hook called 'wpforo_search_result_after'. Here is the place and the arguments:

 

$args: The search query:

$args = array( 
'needle' => '', // search phrase
'forumids' => array(), // array( 2, 10, 25 )
'date_period' => 0, // date period filter
'type' => 'entire-posts', // search type ( entire-posts | titles-only | user-posts | user-topics | tag )
'orderby' => 'relevancy', // search mode by ( relevancy | date | user | forum )
'order' => 'DESC', // search order ( ASC | DESC )
'offset' => NULL, // query offset
'row_count' => NULL // max number of result per page
);

 

$items_count: The total number of search result

$posts: An array of search result posts for current page

$sql: SQL query

Posts: 4
Topic starter
(@cornelraiu)
New Member
Joined: 3 years ago

Hi @robert,

Thank you for the quick reply. That action is exactly what I need to be able to integrate with my plugin.

When should we expect an update for the plugin that would roll-out with this change?

Thank you!

1 Reply
Robert
Admin
(@robert)
Joined: 7 years ago

Support Team
Posts: 9966

@cornelraiu,

We're planning to release it next week.

Posts: 4
Topic starter
(@cornelraiu)
New Member
Joined: 3 years ago

@robert,

Thank you!