Php WordPress。自定义搜索表单查询无法仅从自定义post_类型运行

Php WordPress。自定义搜索表单查询无法仅从自定义post_类型运行,php,wordpress,Php,Wordpress,在我的WordPressV5.5.1中,我有一个自定义的帖子“song”。 我在所有页面的页眉中都有以下搜索表单: <form> <input type="hidden" value="song" name="post_type" id="post_type" /> <input type="text" name="s" id=&q

在我的WordPressV5.5.1中,我有一个自定义的帖子“song”。 我在所有页面的页眉中都有以下搜索表单:

<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>


发现将
get
action
添加到
表单
标签后,解决了以下问题:

<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>

希望这能帮你解决问题。我的问题是
搜索表单在整个网站上都有效;它不仅适用于自定义post_type
song
单页。