I'm new to the "posts_" filter hooks and wanted to know a few things from those in the know:

In this question, someone posted an answer using posts_join that took a second parameter of $query:



function posts_join($join,$query) {


Is this an instance of wp_query or something similar?

Same example:

How would I determine the post type so that I can do custom joins for each custom post type I have on the admin side

What does the posts_fields filter hook do? from the example I've seen, it looks like it replaces the columns in the SELECT clause of an SQL call.

Am I correct in that assumption, and does it too have more parameters that can be called??

I find some examples but I can't get any solid documentation anywhere.

1 Answer 1


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.

  • So basically post_fields replaces the select part of a query. Thank you for the response. Dec 31, 2010 at 20:02
  • Not all of SELECT, it looks like this in code SELECT $found_rows $distinct $fields FROM where $fields variable is passed through posts_fields filter.
    – Rarst
    Dec 31, 2010 at 20:09
  • So, if I were to use the posts_fields filter, how would I access the results?? Is there a way to get to the from thw WP_query class? Jan 2, 2011 at 4:29
  • @Manny Fleurmond if I am not mistaken WP_Query->query() method returns the array of posts you queried for, affected by this filter and all others. They should also be saved in WP_Query->posts field after that.
    – Rarst
    Jan 2, 2011 at 17:12
  • Note that get_posts() defaults to suppressing filters, while query_posts() does not: get_posts() > parameters. Jan 23, 2013 at 1:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.