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

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:

Read More
add_filter('posts_join',array(&$this,'posts_join'),10,2);

...

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.

Related posts

Leave a Reply

1 comment

  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.