2016-12-06 101 views
0

在WordPress中,我使用以下代碼進行搜索。爲什麼搜索沒有顯示

在頭版它工作正常,但在頁面的其餘部分,當我點擊搜索按鈕,它跳到頭版,我也注意到了URL變化

http://www.example.com/post-title/?s=meme

下面是搜索形成。

<form role="search" method="get" action="<?php echo esc_url(home_url('/')); ?>"> 
    <input type="search" value="<?php echo get_search_query() ?>" name="s" title="Search"/> 
    <button type="submit" class="btn btn-default">Search</button> 
</form> 

回答

0

這是發生,因爲WordPress的接受,而不是你使用http://www.example.com/post-title/?s=meme試試下面的代碼

<form role="search" method="get" action=""> 
<input type="search" value="<?php echo get_search_query() ?>" name="s" title="Search"/> 
<button type="submit" class="btn btn-default">Search</button> 

+0

謝謝您的回覆搜索http://www.example.com/?s=meme以下格式。仍然不起作用。 –

+0

在瀏覽器中輸入「http://www.example.com/?s = meme」wordpress不會在您的網站上搜索詞meme嗎? –

+0

是的,這工作正常,http://www.example.com/?s=meme但是,當我點擊搜索按鈕,URL會自動更改爲http://www.example.com/post-title/? S =模因 –