Skip to content
This repository has been archived by the owner on Jun 1, 2019. It is now read-only.

Commit

Permalink
Hopefully resolve search term count issue
Browse files Browse the repository at this point in the history
* Removed transients as this was causing more trouble than it was worth
* Make sure SQL query checks for 'publish' status to resolve wrong counts from what was shown vs displayed
  • Loading branch information
Zach Schnackel committed Feb 28, 2015
1 parent 2518cfe commit a3d7d6a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 15 deletions.
23 changes: 9 additions & 14 deletions inc/search.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,20 +33,15 @@ function basey_get_post_type_count($post_type_name) {
$search_query = get_search_query();
$search_query_db = preg_replace('/[^a-zA-Z0-9.]/', '', $search_query);

$post_type_count = get_transient('basey_search_' . $post_type_name . '_' . $search_query_db );
if (false === $post_type_count) {

// Count number of "total" results returned for each post type
// This is independant of "posts_per_page"
$post_type_count = $wpdb->get_var("
SELECT COUNT(*) FROM $wpdb->posts
WHERE post_type='$post_type_name'
AND ( post_title LIKE '%$search_query%'
OR post_content LIKE '%$search_query%')
");

set_transient( 'basey_search_' . $post_type_name . '_' . $search_query_db, $post_type_count, 60 * 60 );
}
// Count number of "total" results returned for each post type
// This is independant of "posts_per_page"
$post_type_count = $wpdb->get_var("
SELECT COUNT(*) FROM $wpdb->posts
WHERE post_type='$post_type_name'
AND post_status='publish'
AND ( post_title LIKE '%$search_query%'
OR post_content LIKE '%$search_query%')
");

return $post_type_count;
}
Expand Down
1 change: 0 additions & 1 deletion search.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
echo '<ul id="search-nav" class="uk-subnav uk-subnav-pill">';
echo '<li><span>' . __('Filter Results', 'basey') . '</span>';
foreach ( $results['post_types'] as $post_type) {

$post_type_name = $post_type['name'];
$post_type_count = basey_get_post_type_count($post_type_name);

Expand Down

0 comments on commit a3d7d6a

Please sign in to comment.