Skip to content

Commit

Permalink
Merge pull request #3791 from rebeccahum/terms/fix-query-db
Browse files Browse the repository at this point in the history
In Terms Indexable`query_db`, for term count, use `wp_count_terms()` instead of `WP_Term_Query`
  • Loading branch information
felipeelia authored Jan 4, 2024
2 parents afbb9a5 + de5b2b3 commit 48b7fa9
Showing 1 changed file with 12 additions and 17 deletions.
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

0 comments on commit 48b7fa9

Please sign in to comment.