一、 最近发布了2个问题(First, Second) 没有回答。我为他们俩找到了解决办法。但现在是时候对事情进行微调了。如果我能在这里进行微调,我可以回答这两个问题。为什么要微调?因为procedural raw PHP coding 在之前更少WordPress\' way.
<?php
function project_modify_default_search( $query ) {
if( $query->is_search && $query->is_main_query() && ! isset( $_REQUEST[\'search\'] ) ) {
//I\'m in my search.php - confirmed
//Reset default $query - not to execute at all
//Do my custom complex query and pass the query as a $wp_query object
//so that I can use the default search.php template
global $wpdb;
$searchQ = sanitize_text_field( get_query_var( \'s\' ) );
$complex_query = "SELECT SQL_CALC_FOUND_ROWS {$wpdb->posts}.ID ...";
return $custom_search_query = $wpdb->get_results( $complex_query, ARRAY_N );
} //endif
}
add_action( \'pre_get_posts\', \'project_modify_default_search\' );
但实际上,我在两种情况下无法使用上述代码:我无法重置默认查询我无法返回自定义查询以便获取默认查询search.php
完美无瑕地工作,但查询工作正常,我用另一种方式进行了检查。
问题是:
How can I reset the usual $query on the search page to initiate my custom $wpdb
query there?