基本上我正在玩一个插件,允许存档页面上的未来日期帖子。我的问题比这个特定的功能更广泛,但是每个人都喜欢一些背景。在插件中修改wordpress查询的正确方法是什么?
我有许多插件开发概念,但必须缺少一些非常基本的东西。
我可以成功地重写查询,让我结果,我想是这样的:
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');
但是,如果我试图创建主循环后新WP_ Query('different_query_stuff
“)新的查询使用相同的WHERE语句如上所述。
问题是:我错过了什么?
谢谢。