WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Example: I'm trying to modify an instantiation of WP_Query by using the posts_orderby filter like so:

add_filter('posts_orderby', 'favorites_orderby');
$new_query = new WP_Query($args);
remove_filter('posts_orderby', 'favorites_orderby');

the favorites_orderby() function is like so:

function favorites_orderby($post_in){
        $post_in_str = implode(',', $post_in);
    return $post_in_str;

$post_in is an array that changes based on a previous, separate db query, so I need to be able to pass it into the favorites_orderby() function. Basically it's an array of post IDs that need to get fed to the WP_Query instantiation's ORDER BY parameter so that the resulting db request is set like so: ORDER BY FIELD(ID, 6, 18, 90, 12).

Everything works except passing the array of post IDs ($post_in) to the favorites_orderby()

Any help would be greatly appreciated!

share|improve this question
up vote 2 down vote accepted

No, filters get arguments based on the call to the filter. Basically, filters get their inputs from the apply_filters function call.

If you want to pass in data via another means, use a global variable or wrap the code and the data you want to use in an instance of a class.

share|improve this answer
Thanks Otto, appreciate it! – darrinb Aug 4 '11 at 13:27

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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