搜索自定义帖子类型会得到相同的模板页面

时间:2017-07-08 作者:John Paul

我有一个针对产品自定义帖子类型的saperate搜索部分。与分页在同一页内的所需结果。单击saperate页面中显示的任何结果。但都在产品定制帖子、产品页面、产品模板、产品单一。下面是表单和一些代码。

<form role="search" method="get" id="searchform" action="<?php echo esc_url( home_url( \'/\' ) ); ?>">
<div class="row">
<div class="col-md-3">Search Keyword:</div>
<div class="col-md-3"><input type="text" placeholder="Search Product..."></div>
<div class="col-md-2"><input type="submit" id="searchsubmit" value="Searchi"> <input type="hidden" name="post_type" value="product"></div>
</div>
<div class="row">
<lable for="r1"><input type="radio" name="product-filter" id="r1" checked="chcecked"> Any Words</lable>
<lable for="r2"><input type="radio" name="product-filter" id="r2"> All Words</lable>
<lable for="r3"><input type="radio" name="product-filter" id="r3"> Exact Phrase</lable>
</div>
<em>Search term must be a minimum of 3 characters and a maximum of 20 characters</em>
</form>
以下是我的自定义帖子类型

add_action(\'init\', \'product_register\');
function product_register() {
    $args = array(
    \'label\' => __(\'Products\'),
    \'singular_label\' => __(\'Product\'),
    \'public\' => true,
    \'show_ui\' => true,
    \'capability_type\' => \'post\',
    \'hierarchical\' => false,
    \'rewrite\' => true,
    \'supports\' => array(\'title\', \'editor\', \'thumbnail\')
    );

    register_post_type(\'product\', $args);
}
add_action(\'admin_init\', \'admin_init\');
register_taxonomy(\'catalog\', array(\'product\'),
    array(\'hierarchical\' => true,
    \'label\' => \'Catalogs\',
    \'singular_label\' => \'Catalog\',
    \'rewrite\' => true)
);

function admin_init() {
    add_meta_box(\'prodInfo - meta\', \'Product Options\', \'meta_options\', \'product\', \'side\', \'low\');
}
function meta_options() {
    global $post;
    $custom = get_post_custom($post -> ID);
    $price = $custom[\'price\'][0];
    echo \'<label> Price: </label><input type="text" name="price" value="\'. $price .\'"/ > \';
}
function save_price() {
        global $post;
        update_post_meta($post->ID, \'price\', $_POST[\'price\']);
}
add_action(\'save_post\', \'save_price\');
如何在div中显示结果?它还指示我到一个有特定结果的页面。请提供建议或指导?

1 个回复
SO网友:Roshan Deshapriya

1、创建单个-(cpt)。php在你的主题中,复制一个你的单曲。php并根据您的CPT名称对其进行重命名,因此此页面模板将用于显示您的CPT查询。

有关更多详细信息,请参阅wordpress codex。https://codex.wordpress.org/Category_Templates

要创建CPT Arctive页面,请遵循相同的过程。

archive-(cpt).php
对于Taxonimies

taxonomy-(cpt).php
CPT是您的自定义帖子类型名称。

查看下面的文章可以通过ajax获得搜索结果。https://premium.wpmudev.org/blog/how-to-use-ajax-in-wordpress-to-load-search-results/?ptm=c&utm_expid=3606929-108.O6f5ypXuTg-XPCV9sY1yrw.2&utm_referrer=https%3A%2F%2Fwww.google.com%2F

结束

相关推荐

custom search result page

我所做的,我创建搜索。php<?php get_header(); ?> <div class=\"wapper\"> <div class=\"contentarea clearfix\"> <div class=\"content\"> <h1 class=\"search-title\"> <?php echo $wp_query->found_posts; ?>&#