My theme runs a loop that does not require post terms to show. However Wordpress core runs the wp_get_object_terms function on every iteration.
This results in unnecessary DB queries such as:
SELECT t.*, tt.* FROM wp_terms AS t INNER JOIN wp_term_taxonomy AS tt ON tt.term_id = t.term_id INNER JOIN wp_term_relationships AS tr ON tr.term_taxonomy_id = tt.term_taxonomy_id WHERE tt.taxonomy IN ('category') AND tr.object_id IN (81595) ORDER BY t.name ASC
Is there a way to prevent / reduce or optimize the calling of wp_get_object_terms() to only when it is absolutely necessary?
I've tracked it down to get_permalink() which is called within the loop. Our site uses permalinks that include the category, which explains why it is searching for the category for every post. Would there be any way to optimize this?