我知道,通过将&orderby=post_date&order=desc添加到搜索URL中,我们可以轻松地对WP搜索结果排序,如下所示:
https://www.example.com/s=search+terms&orderby=post_date&order=desc
如何在本机实现此功能以搜索我正在使用的表单代码:
<form method="get" action="https://www.example.com/" id="sv2"><input name="s" id="s" size="30" title="Search example.com" type="search" placeholder="Search example.com"></form>
救命啊!
也许functions.php需要一个代码。
发布于 2022-07-25 10:12:58
@KA.MVP您可以为'orderby‘和'order’创建隐藏字段,默认值为'post_date‘、'desc’或'asc‘,您还可以将此表单放入下面解释的add_shortcode函数中,并通过添加简短代码自定义_搜索_表格来使用。
function search_form_func()
{
?>
<form method="get" action="https://www.example.com/" id="sv2">
<input name="s" id="s" size="30" title="Search example.com" type="search" placeholder="Search example.com">
<input type="hidden" name="orderby" value="post_date">
<input type="hidden" name="order" value="desc">
<input type="submit" name="submit" value="Search">
</form>
<?php
}
add_shortcode('custom_search_form','search_form_func');https://wordpress.stackexchange.com/questions/407968
复制相似问题