I am developing a plug-in which stores data in a custom table and is joined onto the wp_posts by the post's the id. I then use the posts_join and post_fields filters to join my table and be able retrieve data from it. For example:
add_filter('posts_join', 'my_join' );
function my_join( $join ){
global $wpdb;
$join .= "LEFT JOIN wp_my_table ON $wpdb->posts.ID = wp_my_table.postID ";
return $join;
}
This works well on the front end (and even most of the admin), but when a post is being edited, the join doesn't seem to happen. For instance, in my plugin's custom metabox on the edit page, var_dump($post) reveals all the standard fields, but none of my plugin's.
When a post is being edited, does it skip the posts_join, posts_fields filters? Is there another hook that can be used?
Update
I have done some further tests. Let's suppose I am on;
../post.php?post=703&action=edit. As in my comment to Chris' response, the the_post hook reveals that the table has been successfully joined at that point (and the post is 703).
On the other hand there are two calls to posts_selection and both are for revision posts that are the children of 703. (I have attempted joining to their parent, but this does not work - even after ensuring filters are not suppressed).
I can, of course, just retrieve my data inside the metabox - but I would like to know if it would be possible to avoid having to do this. (And quite what goes on when click to edit a post :D!)