admin管理员组文章数量:1122846
I have created the custom post type "truck" with custom post type ui plugin. I then created a couple of custom taxonomies "make" and "model". I am using Advanced Custom Fields in the templates to display the output the way I want it. I have everything looking and working the way I want it to.. almost.
I am using the plugin search & filter to allow for filtering by custom taxonomy. So where I am getting hung up is when I try to filter results I have each taxonomy directed at an archive page I created but it is just displaying all results each time. My guess is I have messed up my query somehow but I'm not sure. My code is below, any help appreciated, thanks
This is the archive page to display all listings.
<?php /* Template Name: TruckArchive */ ?>
<?php get_header(); ?>
<div id="container" class="truck-archive">
<div class="title-container">
<h1 class="truck-title"><?php the_title(); ?></h1>
</div>
<div class="row">
<div class="col-md-9">
<div id="content" role="main">
<?php if ( have_posts() ) : the_post; ?>
<?php while ( have_posts() ) : the_post(); ?>
<?php endwhile; ?>
<?php endif; wp_reset_postdata(); ?>
<!-- new query ----- -->
<?php
// Example for adding WP PageNavi to a new WP_Query call
$paged = get_query_var('paged') ? get_query_var('paged') : 1;
$args = array('post_type' => 'truck', 'posts_per_page' => 10, 'paged' => $paged);
$mytrucks = new WP_Query( $args );
while ( $mytrucks->have_posts() ) : $mytrucks->the_post(); ?>
<div class="col-md-12 panel panel-default">
<div class="col-md-4 thumb title">
<?php if ( has_post_thumbnail()) : ?>
<a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>" >
<?php the_post_thumbnail('thumbnail'); ?>
</a>
<?php endif; ?>
</div>
<div class="col-md-4">
<h5><?php the_title(); ?></h5>
<?php echo custom_field_excerpt(); ?>
<ul>
<li><b>Stock #:</b> <?php the_field('stock_number'); ?></li>
<li><b>Engine Manufacturer:</b> <?php the_field('engine_manufacturer'); ?></li>
<li><b>Engine Type:</b> <?php the_field('engine_type'); ?></li>
<li><b>Horsepower:</b> <?php the_field('horsepower'); ?></li>
<li><b>Transmission:</b> <?php the_field('transmission'); ?></li>
</ul>
</div>
<div class="col-md-4">
<h4>Price: $<?php the_field('price'); ?></h4>
<div contact-info-archive>
<span>Title</span><br>
<address>Address</address>
<span>Phone:Phone Number</span><br><br>
<a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>" class="btn btn-default">Learn More</a>
</div>
</div>
</div>
<?php endwhile; ?>
<div class="row">
<div class="col-md-12 text-left">
<?php wp_pagenavi( array( 'query' => $mytrucks ) ); ?>
</div>
</div>
<!-- new query end -->
</div><!-- #content -->
</div>
<div class="col-md-3 search-filter">
<div class="panel panel-default">
<h4>Narrow Your Search</h4>
<?php echo do_shortcode( '[searchandfilter taxonomies="model,make"]' ); ?>
</div>
</div>
</div>
</div><!-- #container -->
<?php get_footer(); ?>
This is the custom taxonomy page "taxonomy-model.php"
<?php
include('archive-truck.php');
?>
This is the custom search results page I am trying to get to display all search results for all custom taxonomies archive-truck.php
<?php get_header(); ?>
<div id="container" class="truck-archive">
<div class="title-container">
<h1 class="truck-title">Search Results</h1>
</div>
<div class="row">
<div class="col-md-9">
<div id="content" role="main">
<?php $mytrucks = new WP_Query(array(
'post_type' => 'truck'
)); ?>
<?php while ($mytrucks->have_posts()) : $mytrucks->the_post(); ?>
<div class="col-md-12 panel panel-default">
<div class="col-md-4 thumb title">
<?php if ( has_post_thumbnail()) : ?>
<a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>" >
<?php the_post_thumbnail('thumbnail'); ?>
</a>
<?php endif; ?>
</div>
<div class="col-md-4">
<h5><?php the_title(); ?></h5>
<?php echo custom_field_excerpt(); ?>
<ul>
<li><b>Stock #:</b> <?php the_field('stock_number'); ?></li>
<li><b>Engine Manufacturer:</b> <?php the_field('engine_manufacturer'); ?></li>
<li><b>Engine Type:</b> <?php the_field('engine_type'); ?></li>
<li><b>Horsepower:</b> <?php the_field('horsepower'); ?></li>
<li><b>Transmission:</b> <?php the_field('transmission'); ?></li>
</ul>
</div>
<div class="col-md-4">
<h4>Price: $<?php the_field('price'); ?></h4>
<div contact-info-archive>
<span>Title</span><br>
<address>Address</address>
<span>Phone:Phone Number</span><br>
<a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>" class="btn btn-default">Learn More</a>
</div>
</div>
</div>
<?php endwhile; ?>
</div><!-- #content -->
</div>
<div class="col-md-3 search-filter">
<div class="panel panel-default">
<?php echo do_shortcode( '[searchandfilter taxonomies="model,make"]' ); ?>
</div>
</div>
</div>
</div><!-- #container -->
<?php get_footer(); ?>
I have created the custom post type "truck" with custom post type ui plugin. I then created a couple of custom taxonomies "make" and "model". I am using Advanced Custom Fields in the templates to display the output the way I want it. I have everything looking and working the way I want it to.. almost.
I am using the plugin search & filter to allow for filtering by custom taxonomy. So where I am getting hung up is when I try to filter results I have each taxonomy directed at an archive page I created but it is just displaying all results each time. My guess is I have messed up my query somehow but I'm not sure. My code is below, any help appreciated, thanks
This is the archive page to display all listings.
<?php /* Template Name: TruckArchive */ ?>
<?php get_header(); ?>
<div id="container" class="truck-archive">
<div class="title-container">
<h1 class="truck-title"><?php the_title(); ?></h1>
</div>
<div class="row">
<div class="col-md-9">
<div id="content" role="main">
<?php if ( have_posts() ) : the_post; ?>
<?php while ( have_posts() ) : the_post(); ?>
<?php endwhile; ?>
<?php endif; wp_reset_postdata(); ?>
<!-- new query ----- -->
<?php
// Example for adding WP PageNavi to a new WP_Query call
$paged = get_query_var('paged') ? get_query_var('paged') : 1;
$args = array('post_type' => 'truck', 'posts_per_page' => 10, 'paged' => $paged);
$mytrucks = new WP_Query( $args );
while ( $mytrucks->have_posts() ) : $mytrucks->the_post(); ?>
<div class="col-md-12 panel panel-default">
<div class="col-md-4 thumb title">
<?php if ( has_post_thumbnail()) : ?>
<a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>" >
<?php the_post_thumbnail('thumbnail'); ?>
</a>
<?php endif; ?>
</div>
<div class="col-md-4">
<h5><?php the_title(); ?></h5>
<?php echo custom_field_excerpt(); ?>
<ul>
<li><b>Stock #:</b> <?php the_field('stock_number'); ?></li>
<li><b>Engine Manufacturer:</b> <?php the_field('engine_manufacturer'); ?></li>
<li><b>Engine Type:</b> <?php the_field('engine_type'); ?></li>
<li><b>Horsepower:</b> <?php the_field('horsepower'); ?></li>
<li><b>Transmission:</b> <?php the_field('transmission'); ?></li>
</ul>
</div>
<div class="col-md-4">
<h4>Price: $<?php the_field('price'); ?></h4>
<div contact-info-archive>
<span>Title</span><br>
<address>Address</address>
<span>Phone:Phone Number</span><br><br>
<a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>" class="btn btn-default">Learn More</a>
</div>
</div>
</div>
<?php endwhile; ?>
<div class="row">
<div class="col-md-12 text-left">
<?php wp_pagenavi( array( 'query' => $mytrucks ) ); ?>
</div>
</div>
<!-- new query end -->
</div><!-- #content -->
</div>
<div class="col-md-3 search-filter">
<div class="panel panel-default">
<h4>Narrow Your Search</h4>
<?php echo do_shortcode( '[searchandfilter taxonomies="model,make"]' ); ?>
</div>
</div>
</div>
</div><!-- #container -->
<?php get_footer(); ?>
This is the custom taxonomy page "taxonomy-model.php"
<?php
include('archive-truck.php');
?>
This is the custom search results page I am trying to get to display all search results for all custom taxonomies archive-truck.php
<?php get_header(); ?>
<div id="container" class="truck-archive">
<div class="title-container">
<h1 class="truck-title">Search Results</h1>
</div>
<div class="row">
<div class="col-md-9">
<div id="content" role="main">
<?php $mytrucks = new WP_Query(array(
'post_type' => 'truck'
)); ?>
<?php while ($mytrucks->have_posts()) : $mytrucks->the_post(); ?>
<div class="col-md-12 panel panel-default">
<div class="col-md-4 thumb title">
<?php if ( has_post_thumbnail()) : ?>
<a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>" >
<?php the_post_thumbnail('thumbnail'); ?>
</a>
<?php endif; ?>
</div>
<div class="col-md-4">
<h5><?php the_title(); ?></h5>
<?php echo custom_field_excerpt(); ?>
<ul>
<li><b>Stock #:</b> <?php the_field('stock_number'); ?></li>
<li><b>Engine Manufacturer:</b> <?php the_field('engine_manufacturer'); ?></li>
<li><b>Engine Type:</b> <?php the_field('engine_type'); ?></li>
<li><b>Horsepower:</b> <?php the_field('horsepower'); ?></li>
<li><b>Transmission:</b> <?php the_field('transmission'); ?></li>
</ul>
</div>
<div class="col-md-4">
<h4>Price: $<?php the_field('price'); ?></h4>
<div contact-info-archive>
<span>Title</span><br>
<address>Address</address>
<span>Phone:Phone Number</span><br>
<a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>" class="btn btn-default">Learn More</a>
</div>
</div>
</div>
<?php endwhile; ?>
</div><!-- #content -->
</div>
<div class="col-md-3 search-filter">
<div class="panel panel-default">
<?php echo do_shortcode( '[searchandfilter taxonomies="model,make"]' ); ?>
</div>
</div>
</div>
</div><!-- #container -->
<?php get_footer(); ?>
Share
Improve this question
asked Nov 2, 2016 at 14:42
jfoutchjfoutch
1012 bronze badges
0
1 Answer
Reset to default 0I added this code before my loop and separated the custom taxonomy templates rather than pointing them to one general search template to display results based on the current taxonomy. Hope this helps someone.
$current_cat = get_query_var('model');
$args = array(
'post_type' => 'truck',
'model' => $current_cat
);
query_posts($args);
本文标签: How to make a custom search template for custom taxonomy
版权声明:本文标题:How to make a custom search template for custom taxonomy? 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736283225a1926897.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论