WordPress搜索按帖子类型过滤

时间:2019-07-18 10:50:09

标签: php wordpress search

通过过滤来自不同帖子类型的搜索结果,我遇到了问题。我的代码适用于帖子类型“ post”,“ glossar”和“ product”,但不适用于“ page”。有人知道为什么吗?

<form role="search" method="get" class="search-result-form" id="searchform" action="<?php echo home_url( '/' ); ?>">
    <input autocomplete="off" class="search-input" type="text" name="s" id="s" placeholder="<?php _e( 'To search, type and hit enter.', 'html5blank' ); ?>" <?php if(is_search()) { ?>value="<?php the_search_query(); ?>" <?php } else { ?>value="<?php _e( 'To search, type and hit enter.', 'html5blank' ); ?>" onfocus="if(this.value==this.defaultValue)this.value='';" onblur="if(this.value=='')this.value=this.defaultValue;"<?php } ?> /><br />

    <?php $query_types = get_query_var('post_type'); ?>
    <input type="checkbox" id="page2" name="post_type[]" value="page" <?php if (in_array('page', $query_types)) { echo 'checked="checked"'; } ?> /><label for="page2">Seiten</label>
    <input type="checkbox" id="post2" name="post_type[]"  value="post" <?php if (in_array('post', $query_types)) { echo 'checked="checked"'; } ?> /><label for="post2">Blog</label>
    <input type="checkbox" id="glossar2" name="post_type[]" value="glossar" <?php if (in_array('glossar', $query_types)) { echo 'checked="checked"'; } ?> /><label for="glossar2">Glossar</label>
    <input type="checkbox" id="product2" name="post_type[]" value="product" <?php if (in_array('product', $query_types)) { echo 'checked="checked"'; } ?> /><label for="product2">Produkte</label>
    <button class="search-submit" type="submit" role="button"><?php _e( 'Search', 'html5blank' ); ?></button>
</form>

0 个答案:

没有答案