Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save j100002ben/2761739 to your computer and use it in GitHub Desktop.
Save j100002ben/2761739 to your computer and use it in GitHub Desktop.
Example of "posts_clauses_request" filter
function search_posts_clauses_request($clauses, $wp_query){
global $wpdb;
if(is_plugin_active('wp-cjk-fulltext-index/wp-cjk-fulltext-index.php')){
$key = get_query_var('key');
cjkfxi_set_posts_clauses_request($clauses, $key);
}
extract($clauses, EXTR_SKIP);
$found_posts_query = " SELECT COUNT(*) FROM $wpdb->posts $join WHERE 1=1 $where";
$wp_query->found_posts = $wpdb->get_var( $found_posts_query );
$wp_query->found_posts = apply_filters_ref_array( 'found_posts', array( $wp_query->found_posts, &$wp_query ) );
$wp_query->max_num_pages = ceil($wp_query->found_posts / $wp_query->query_vars['posts_per_page']);
remove_filter('posts_clauses_request', 'search_posts_clauses_request', 10, 2);
return $clauses;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment