【问题标题】:WordPress. Custom search form query not working from custom post_type onlyWordPress。自定义搜索表单查询仅从自定义 post_type 不起作用
【发布时间】:2021-01-10 18:14:56
【问题描述】:

在我的 WordPress v5.5.1 中,我有自定义帖子“歌曲”。 我在所有页面的标题中都有以下搜索表单:

<form>
    <input type="hidden" value="song" name="post_type" id="post_type" />
    <input type="text" name="s" id="search" value="<?php the_search_query(); ?>">
</form>

搜索结果显示在search.php

搜索表单适用于除自定义 post_type 页面www.example.com/song/song-1 之外的所有页面,搜索查询转到未找到的 404 页面。

【问题讨论】:

  • wordpress.stackexchange.com/questions/29857/…希望这能帮助您解决问题
  • 没有。我的问题是带有&lt;input type="hidden" value="song" name="post_type" id="post_type" /&gt; 的搜索表单可以在整个网站上使用;它不仅适用于自定义 post_type song 单页。

标签: php wordpress


【解决方案1】:

发现在form标签中添加getaction后,问题解决了:

<form class="search-form" method="get" action="<?php echo bloginfo('url') ?>">
    <input type="hidden" value="song" name="post_type" id="post_type" />
    <input type="text" name="s" id="search" value="<?php the_search_query(); ?>">
</form>

【讨论】:

    猜你喜欢
    • 2017-04-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-12-18
    • 1970-01-01
    • 1970-01-01
    • 2016-10-05
    • 1970-01-01
    相关资源
    最近更新 更多