[wp-hackers] meta_key and meta_value query variables don't work in the backend?

Peter Westwood peter.westwood at ftwr.co.uk
Fri Jan 15 21:49:28 UTC 2010


On 15 Jan 2010, at 19:24, Matthew Gerring wrote:

> What I mean is, I'm writing a plugin to allow a client to sort pages  
> on the edit pages screen. I have it set up to sort by author, title,  
> and date, and filter by a custom taxonomy. I want to be able to sort  
> by custom field as well- all of the pages in this site have a custom  
> field called "Country" with a set drop-down list of countries.
>
> To do all the sorting and filtering so far, I used the  
> manage_pages_query hook to add query variables to the request, and  
> it has worked perfectly. All it does is put all the query variables  
> in an array and pass it to the wp() function. But if I try to use  
> the meta_key and meta_value variables, which are available if I use  
> them in a theme (i.e. in the front end), nothing happens. So it  
> appears that while you can pull out posts according to custom fields  
> in a theme, you can't do the same thing on the manage pages/posts  
> screens in the back end, and I'm wondering why.
>


Bear in mind that the wp() call only accept query vars which are  
specified in the $public_query_vars and $private_query_vars arrays  
which are part of the WP class and these don't include anything to do  
with post_meta.

The public_query_vars are those which can be specified in a url and  
the private_query_vars are the extra ones which can be specified only  
by code

You will need to extend the list of private_query_vars which it  
supports to get the post_meta ones passed thorugh.

Cheers
-- 
Peter Westwood
http://blog.ftwr.co.uk | http://westi.wordpress.com
C53C F8FC 8796 8508 88D6 C950 54F4 5DCD A834 01C5



More information about the wp-hackers mailing list