Technical Mid Level

Explain how WP_Query works. How do you write efficient custom queries, and what pitfalls should you watch for with meta queries and tax queries?

Quick Tip

Show awareness of the cost: "Meta queries JOIN the postmeta table for every key. I move filterable data into taxonomies where possible and set no_found_rows to true on queries that do not need pagination to skip the COUNT query."

What good answers include

WP_Query builds SQL from arguments like post_type, posts_per_page, tax_query, and meta_query. Meta queries are slow by default because postmeta has no composite indexes — querying by multiple meta keys generates JOINs that scale poorly. Tax queries are generally faster because term_relationships is indexed. Optimisation: use taxonomy-based filtering over meta queries where possible, add custom database indexes for frequently queried meta keys, use fields => ids when you only need post IDs, and set no_found_rows => true when you do not need pagination totals. Strong candidates discuss: pre_get_posts for modifying the main query, the difference between main query and secondary queries, and when to use get_posts() versus new WP_Query().

What interviewers are looking for

Tests database awareness in WordPress. Candidates who use meta_query for everything without understanding the performance cost will build slow sites. Those who know when to use taxonomies versus meta and how to optimise queries demonstrate real experience.

← All WordPress questions