[wp-hackers] Custom post types filtering

Olivier autremonde75 at gmail.com
Tue Jun 29 16:38:53 UTC 2010


So actually, it is feasible. I found the trick.

You need to hook there :
add_filter('posts_where','my_posts_where');

And then use this filtering function :
function my_posts_where($where)
{
	global $wpdb, $current_user, $wp_version;

	if ($wp_version >= '3.0' && is_admin() && $_GET['post_type'] ==
'my_post_type')
	{
	       $where = str_replace($wpdb->posts.".post_type = 'my_post_type'
AND",$wpdb->posts.".post_type = 'my_post_type' AND ".$wpdb-
>posts.".post_author = ".$current_user->ID." AND", $where);
	}

	return($where);
}

And you are done!

Now I am wondering how to remove or update the custom post type
numbers at the top as they aren't relevant anymore with this kind of
filtering.


More information about the wp-hackers mailing list