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

I hope this makes any type of sense. I want to be able to add clauses to a specific query object without effecting the main loop on a page, for example for content in a side bar or footer. Is it possible?

share|improve this question
What exactly to you want to acchieve? Maybe there's an easier way with normal query args? – kaiser May 18 '11 at 1:02
I have two post types, one that will be sorted by a parent post title, a taxonomy and a meta vale and one by a parent post title, a taxonomy and two separate meta values. I didn't think WP was robust enough via the query args, so I'm using the post_clauses hook. – Manny Fleurmond May 18 '11 at 1:16
up vote 3 down vote accepted

The most reliable way is to define your own query var and then check it:

$my_query = new WP_Query( array(
  'context' => 'my_query'
) );

Then, from your callback:

function alter_post_clauses( $clauses, $wp_query ) {
  if ( 'my_query' == $wp_query->get( 'context' ) ) {
    // do stuff

  return $clauses;
add_filter( 'posts_clauses', 'alter_post_clauses', 10, 2 );
share|improve this answer
hmm, that works. Thanks, scribu. Deceptively simple coding wins again. – Manny Fleurmond May 18 '11 at 4:01

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.