What is the right way to modify a wordpress query in a plugin?
Posted
by starepod
on Stack Overflow
See other posts from Stack Overflow
or by starepod
Published on 2009-08-21T17:25:05Z
Indexed on
2010/05/29
12:02 UTC
Read the original article
Hit count: 111
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.
© Stack Overflow or respective owner