Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

In Terms Indexablequery_db, for term count, use wp_count_terms() instead of WP_Term_Query #3791

Merged
merged 2 commits into from
Jan 4, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 12 additions & 17 deletions includes/classes/Indexable/Term/Term.php
Original file line number Diff line number Diff line change
Expand Up @@ -620,14 +620,16 @@ public function prepare_document( $term_id ) {
* @return array
*/
public function query_db( $args ) {

$defaults = [
'number' => $this->get_bulk_items_per_page(),
'offset' => 0,
'orderby' => 'id',
'order' => 'desc',
'taxonomy' => $this->get_indexable_taxonomies(),
'hide_empty' => false,
'number' => $this->get_bulk_items_per_page(),
'offset' => 0,
'orderby' => 'id',
'order' => 'desc',
'taxonomy' => $this->get_indexable_taxonomies(),
'hide_empty' => false,
'hierarchical' => false,
'update_term_meta_cache' => false,
'cache_results' => false,
];

if ( isset( $args['per_page'] ) ) {
Expand All @@ -650,23 +652,16 @@ public function query_db( $args ) {
unset( $all_query_args['offset'] );
unset( $all_query_args['fields'] );

/**
* This just seems so inefficient.
*
* @todo Better way to do this?
*/

/**
* Filter database arguments for term count query
*
* @hook ep_term_all_query_db_args
* @param {array} $args Query arguments based to WP_Term_Query
* @param {array} $args Query arguments based to `wp_count_terms()`
* @since 3.4
* @return {array} New arguments
*/
$all_query = new WP_Term_Query( apply_filters( 'ep_term_all_query_db_args', $all_query_args, $args ) );

$total_objects = count( $all_query->terms );
$total_objects = wp_count_terms( apply_filters( 'ep_term_all_query_db_args', $all_query_args, $args ) );
$total_objects = ! is_wp_error( $total_objects ) ? (int) $total_objects : 0;

if ( ! empty( $args['offset'] ) ) {
if ( (int) $args['offset'] >= $total_objects ) {
Expand Down
Loading