Skip to content

lazy_load_term_meta query param is always true #60

@nickdaugherty

Description

@nickdaugherty

Due to how WP_Query initializes default query parameters, and ES WP Query's interaction with WP Query, the lazy_load_term_meta param ends up always being set to true when the internal query to fetch posts by id runs.

This ends up triggering get_the_terms() excessively, which leads to high numbers of cache and/or db reads.

The problem can be most readily seen by watching the $q var here:

$q = $query->query = $this->original_query_args;
$query->parse_query();
$q = array_merge( $current_query_vars, $q );

Before $query->parse_query(); is run, lazy_load_term_meta is still false...yet after it has flipped to true.

As a workaround, it can be bypassed with a filter like this:

add_filter( 'pre_get_posts', function( &$query ) {
   $query->set( 'lazy_load_term_meta', false );

   return $query;
}, 9999 );

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions