Site icon Hip-Hop Website Design and Development

How to make a custom search template for custom taxonomy?

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(); ?>