WordPress不包括搜索頁面
問題描述:
The WP search functionality is only returning posts, not pages.
I think it\'s an issue with my WP theme. I have another WP site where it\'s fine.
One solution here suggested this in functions.php:
1 2 3 4 5 6 7 8 9 |
// include pages in search function filter_search($query) { if ($query->is_search) { $query->set(\'post_type\', array(\'post\', \'page\')); }; return $query; }; add_filter(\'pre_get_posts\', \'filter_search\'); |
That works, but it causes my admin searches in the media library to turn up zero results. Any way to restrict the above to front end searches?
Or maybe there\'s something I can look for in the theme that could be causing this? It\'s a premium theme, complex, not obvious to me where to look. (my support has expired)
圖片轉代碼服務由CSDN問答提供
感謝您的意見,我們儘快改進~
功能建議
WP搜索功能僅返回帖子,而不是頁面。</ p>
I 認為這是我的WP主題的一個問題。 我有另一個WP網站,沒關係。</ p>
這裡的一個解決方案建議在functions.php中使用:</ p>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
//包含搜索頁面 function filter_search($ query){ if($ query-&gt; is_search){ $ query-&gt; set(\'post_type\',array(\'post\',\'page\')); }; \\ n返回$ query; }; add_filter(\'pre_get_posts\',\'filter_search\'); </ code> </ pre> <p>這有效,但它會導致我在媒體上進行管理員搜索 庫結果為零。 有什麼方法可以限制上面到前端的搜索嗎?</ p> <p>或許我可以在主題中尋找可能導致此問題的內容? 這是一個高級主題,複雜,對我來說並不明顯。 (我的支持已過期)</ p> </ div> <h5>網友觀點:</h5> <div> <p>Try this code.</p> <pre><code>function filter_search($query) { if ($query->is_search && !is_admin() ) { $query->set(\'post_type\',array(\'post\',\'page\')); } return $query; } add_filter(\'pre_get_posts\',\'filter_search\'); |
由於網站搬家,部分鏈接失效,如無法下載,請聯繫站長!謝謝支持!
1. 帶 [親測] 說明源碼已經被站長親測過!
2. 下載後的源碼請在24小時內刪除,僅供學慣用途!
3. 分享目的僅供大家學習和交流,請不要用於商業用途!
4. 本站資源售價只是贊助,收取費用僅維持本站的日常運營所需!
5. 本站所有資源來源於站長上傳和網路,如有侵權請郵件聯繫站長!
6. 沒帶 [親測] 代表站長時間緊促,站長會保持每天更新 [親測] 源碼 !
7. 盜版ripro用戶購買ripro美化無擔保,若設置不成功/不生效我們不支持退款!
8. 本站提供的源碼、模板、插件等等其他資源,都不包含技術服務請大家諒解!
9. 如果你也有好源碼或者教程,可以到審核區發布,分享有金幣獎勵和額外收入!
10.如果您購買了某個產品,而我們還沒來得及更新,請聯繫站長或留言催更,謝謝理解 !
GG資源網 » WordPress不包括搜索頁面
1. 帶 [親測] 說明源碼已經被站長親測過!
2. 下載後的源碼請在24小時內刪除,僅供學慣用途!
3. 分享目的僅供大家學習和交流,請不要用於商業用途!
4. 本站資源售價只是贊助,收取費用僅維持本站的日常運營所需!
5. 本站所有資源來源於站長上傳和網路,如有侵權請郵件聯繫站長!
6. 沒帶 [親測] 代表站長時間緊促,站長會保持每天更新 [親測] 源碼 !
7. 盜版ripro用戶購買ripro美化無擔保,若設置不成功/不生效我們不支持退款!
8. 本站提供的源碼、模板、插件等等其他資源,都不包含技術服務請大家諒解!
9. 如果你也有好源碼或者教程,可以到審核區發布,分享有金幣獎勵和額外收入!
10.如果您購買了某個產品,而我們還沒來得及更新,請聯繫站長或留言催更,謝謝理解 !
GG資源網 » WordPress不包括搜索頁面