Explanation of the “posts_join” and “posts_fields” filter hooks?

When you use one of the methods to query for posts (query_posts(), get_posts() or WP_Query object) arguments you provide are processed and turned into SQL query. This happens in WP_Query->&get_posts() method.

Since arguments are not omnipotent there are a lot of hooks in there that allow to modify or override parts of resulting SQL query.

  • posts_join is part of query that handles SQL JOINs – adding additional tables to the mix, for example tables related to taxonomies when they are needed.

  • posts_fields seem to control which database fields will be returned in query, it seems to default to all fields from posts table.

Leave a Comment