好的,我找到一个解决方案。我使用posts_where
筛选输入pre_get_posts
. 使用此筛选器,我可以删除与WHERE
默认SQL查询的一部分。
function custom_loops($query) {
if (is_tax( \'service_photo_location\' )){
$query->set( \'posts_per_page\', 10);
$query->set( \'post__in\', $ids);
$query->set( \'orderby\', \'title\');
$query->set( \'order\', \'ASC\');
add_filter( \'posts_where\', function ( $where ) {
$where = str_replace("AND ( wp_term_relationships.term_taxonomy_id IN (778) )", "", $where);
return $where;
}, 10, 2 );
}
remove_action( \'pre_get_posts\', \'custom_loops\' );
}
add_action(\'pre_get_posts\', \'custom_loops\');