Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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

1 Answer 1

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

 
discard

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.