views:

63

answers:

2

Basically i am playing with a plugin that allows future-dated posts on archive pages. My question is broader than this specific functionality, but everyone likes some context.

I have my head around many of the plugin development concepts, but must be missing something very basic.

I can successfully rewrite a query that gives me the results i want like this:

function modify_where( $where ) {
  global $wp_query;
    // define $year, $cat, etc
  if( is_archive() ) {
    $where = "  AND YEAR(wp_posts.post_date)='".$year."' AND wp_term_taxonomy.taxonomy = 'category' AND wp_term_taxonomy.term_id IN ('".$cat."') AND wp_posts.post_type = 'post' AND (wp_posts.post_status = 'publish' OR wp_posts.post_status = 'future')";
  }
  return $where;
}

add_filter('posts_where', 'catCal_where' );

However, if i attempt to create a new WP_Query('different_query_stuff') after the main loop the new query uses the same WHERE statement outlined above.

The question is : What am I missing?

Thanks.

A: 

Just a guess, as I'm not a WP expert, but maybe rewind_posts, from Function Reference WP_Query

rewind_posts()
Resets $current_post and $post.
songdogtech
A: 

What you probably want to do is remove that filter at the wp action. Add an action at wp, add_action('wp','my_remove_filter_action',999) and have that 'my_remove_filter_action' remove the filter you put on the query so that it effects the page query and is then rendered inert for the rest of the page load.

You might be able to find some other filter that fires earlier than WP to remove the filter on as well. You essentially want to try to restrict that query to the main page query only.

Gipetto