Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/228.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 更新wordpress搜索查询_Php_Wordpress_Search - Fatal编程技术网

Php 更新wordpress搜索查询

Php 更新wordpress搜索查询,php,wordpress,search,Php,Wordpress,Search,我是否可以覆盖或扩展wordpress的搜索查询 当前的搜索如下所示: http://my-wp-site/?s=test&cp_city=Alaminos&sa=search&scat=0 在我的theme search.php中,我试图打印$wp\u查询,它返回: ...... WP_Query Object ( [query] => Array ( [s] => test [scat] => 0 ) [query_vars] =&

我是否可以覆盖或扩展wordpress的搜索查询

当前的搜索如下所示:

http://my-wp-site/?s=test&cp_city=Alaminos&sa=search&scat=0
在我的theme search.php中,我试图打印
$wp\u查询
,它返回:

......
        WP_Query Object ( [query] => Array ( [s] => test [scat] => 0 ) [query_vars] => Array ( [s] => test [scat] => 0 [error] => [m] => [p] => 0 [post_parent] => [subpost] => [subpost_id] => [attachment] => [attachment_id] => 0 [name] => [static] => [pagename] => [page_id] => 0 [second] => [minute] => [hour] => [day] => 0 [monthnum] => 0 [year] => 0 [w] => 0 [category_name] => [tag] => [cat] => [tag_id] => [author] => [author_name] => [feed] => [tb] => [paged] => 0 [comments_popup] => [meta_key] => [meta_value] => [preview] => [sentence] => [fields] => [menu_order] => [category__in] => Array ( ) [category__not_in] => Array ( ) [category__and] => Array ( ) [post__in] => Array ( ) [post__not_in] => Array ( ) [tag__in] => Array ( ) [tag__not_in] => Array ( ) [tag__and] => Array ( ) [tag_slug__in] => Array ( ) [tag_slug__and] => Array ( ) [post_parent__in] => Array ( ) [post_parent__not_in] => Array ( ) [author__in] => Array ( ) [author__not_in] => Array ( ) [ignore_sticky_posts] => [suppress_filters] => [cache_results] => 1 [update_post_term_cache] => 1 [update_post_meta_cache] => 1 [post_type] => any [posts_per_page] => 10 [nopaging] => [comments_per_page] => 50 [no_found_rows] => [search_terms_count] => 1 [search_terms] => Array ( [0] => test ) [search_orderby_title] => Array ( [0] => zfy_posts.post_title LIKE '%test%' ) [order] => DESC ) [tax_query] => WP_Tax_Query Object ( [queries] => Array ( ) [relation] => AND ) [meta_query] => WP_Meta_Query Object ( [queries] => Array ( ) [relation] => ) [date_query] => [queried_object] => [queried_object_id] => 0 [request] => SELECT SQL_CALC_FOUND_ROWS zfy_posts.ID FROM zfy_posts INNER JOIN zfy_term_relationships AS r ON (zfy_posts.ID = r.object_id) INNER JOIN zfy_term_taxonomy AS x ON (r.term_taxonomy_id = x.term_taxonomy_id) AND (x.taxonomy = 'ad_tag' OR x.taxonomy = 'ad_cat' OR 1=1) INNER JOIN zfy_postmeta AS m ON (zfy_posts.ID = m.post_id) INNER JOIN zfy_terms AS t ON x.term_id = t.term_id WHERE 1=1 AND (((zfy_posts.post_title LIKE '%test%') OR (zfy_posts.post_content LIKE '%test%') OR ((t.name LIKE '%test%')) OR ((t.slug LIKE '%test%')) OR ((m.meta_key = 'cp_price') AND (m.meta_value LIKE '%test%')) OR ((m.meta_key = 'cp_street') AND (m.meta_value LIKE '%test%')) OR ((m.meta_key = 'cp_city') AND (m.meta_value LIKE '%test%')) OR ((m.meta_key = 'cp_state') AND (m.meta_value LIKE '%test%')) OR ((m.meta_key = 'cp_country') AND (m.meta_value LIKE '%test%')) OR ((m.meta_key = 'cp_zipcode') AND (m.meta_value LIKE '%test%')) OR ((m.meta_key = 'cp_region') AND (m.meta_value LIKE '%test%')) OR ((m.meta_key = 'cp_size') AND (m.meta_value LIKE '%test%')) OR ((m.meta_key = 'cp_feedback') AND (m.meta_value LIKE '%test%')) OR ((m.meta_key = 'cp_currency') AND (m.meta_value LIKE '%test%')))) AND (zfy_posts.post_status = 'publish') AND (zfy_posts.post_type IN ('ad_listing','post','page')) GROUP BY zfy_posts.ID ORDER BY zfy_posts.post_title LIKE '%test%' DESC, zfy_posts.post_date DESC LIMIT 0, 10 [posts] => Array ( [0] => WP_Post Object ( [ID] => 92 [post_author] => 4 [post_date] => 2014-02-22 12:33:40 [post_date_gmt] => 2014-02-22 12:33:40 [post_content] =>
        fg fdgfdg
    .......
我是否可以在functions.php或search.php中覆盖它?我只想添加
cp\u city
值的GET值,并将其替换为
…或((m.meta\u key='cp\u city')和(m.meta\u值,如“%test%”)从当前的
$wp\u查询中删除)
。。。这将类似于
…或((m.meta\u key='cp\u city')和(m.meta\u值类似于'$\u GET[“cp\u city”]')…


我一直在寻找使用搜索查询的当前函数,但还没有找到它,所以我一直在寻找扩展或覆盖它的原因

您可以覆盖模板中的
$wp\u query
变量

从文档中修改:

$args = array(
    'post_type' => 'my_custom_post_type',
    'meta_key' => 'cp_city',
    'orderby' => 'meta_value_num',
    'order' => 'ASC',
    'meta_query' => array(
        array(
            'key' => 'cp_city',
            'value' => $_GET['cp_city'],
        )
    )
);
$wp_query = new WP_Query($args);
在页面中搜索
'meta\u query'