Skip to content

Instantly share code, notes, and snippets.

@braginteractive
Created June 17, 2019 14:18
Show Gist options
  • Save braginteractive/1c911287fb4f243792e9581e6544eee3 to your computer and use it in GitHub Desktop.
Save braginteractive/1c911287fb4f243792e9581e6544eee3 to your computer and use it in GitHub Desktop.
WordPress archive page for custom post type with filter
<?php
/**
* The template for displaying archive pages
*
* @link https://codex.wordpress.org/Template_Hierarchy
*
* @package WP Theme
*/
get_header(); ?>
<?php
/** Get the URL parameter **/
$queryTitle = '';
$queryTitle = get_query_var('business_category');
?>
<div class="page-header d-flex align-items-center bg-primary text-white mb-5">
<div class="container">
<header class="entry-header text-center">
<h1><?php single_term_title(); ?> <?php echo $queryTitle; ?></h1>
</header><!-- .entry-header -->
</div><!-- .container -->
</div><!-- .page-header -->
<div class="container">
<?php if($queryTitle == '') : ?>
<div class="row mt-4">
<div class="col-md-6">
<?php
$taxonomy = 'business_category';
$cat_args = array(
'taxonomy' => $taxonomy,
'hide_empty' => true
);
$terms = get_terms($cat_args);
$counter = 0;
if ( $terms && !is_wp_error( $terms ) ) :
?>
<div class="input-group mb-3">
<div class="input-group-prepend">
<label class="input-group-text" for="inputFilter">Filter by Specialty:</label>
</div>
<select class="custom-select custom-select-lg" id="inputFilter" onchange="if (this.value) window.location.href=this.value">
<option selected disabled="disabled">Select...</option>
<?php foreach ( $terms as $term ) { ?>
<option value="<?php echo get_term_link($term->slug, $taxonomy); ?>"><?php echo $term->name; ?> </option>
<?php } ?>
</select>
</div>
<?php endif; ?>
</div><!-- .col-md-6 -->
<div class="col-md-6">
<?php
$taxonomy = 'business_city';
$cat_args = array(
'taxonomy' => $taxonomy,
'hide_empty' => true
);
$terms = get_terms($cat_args);
$counter = 0;
if ( $terms && !is_wp_error( $terms ) ) :
?>
<div class="input-group mb-3">
<div class="input-group-prepend">
<label class="input-group-text" for="inputFilter">Filter by City:</label>
</div>
<select class="custom-select custom-select-lg" id="inputFilter" onchange="if (this.value) window.location.href=this.value">
<option selected disabled="disabled">Select...</option>
<?php foreach ( $terms as $term ) { ?>
<option value="<?php echo get_term_link($term->slug, $taxonomy); ?>"><?php echo $term->name; ?> </option>
<?php } ?>
</select>
</div>
<?php endif; ?>
</div><!-- .col-md-6 -->
</div><!--row-->
<?php endif; ?>
<div id="primary">
<main id="main" class="site-main py-3" role="main">
<?php
if ( have_posts() ) : ?>
<div class="row">
<?php
/* Start the Loop */
while ( have_posts() ) : the_post();
/*
* Include the Post-Format-specific template for the content.
* If you want to override this in a child theme, then include a file
* called content-___.php (where ___ is the Post Format name) and that will be used instead.
*/
get_template_part( 'template-parts/content', 'biz' );
endwhile;
else :
get_template_part( 'template-parts/content', 'none' );
endif; ?>
</div><!-- .row -->
<div class="row">
<div class="col-md-12">
<?php the_posts_pagination( array(
'prev_text' => '<i class="fas fa-arrow-left"></i><span class="screen-reader-text">' . __( 'Previous Page', 'helpwp' ) . '</span>',
'next_text' => '<span class="screen-reader-text">' . __( 'Next Page', 'helpwp' ) . '</span><i class="fas fa-arrow-right"></i>',
) ); ?>
</div><!-- .col-md-12 -->
</div><!-- .row -->
</main><!-- #main -->
</div><!-- #primary -->
</div>
<?php
get_footer();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment