Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // Get all categories for the gallery
- $categories = get_terms('dez_gallery_category', array(
- 'hide_empty' => false,
- ));
- // Get all industries for the gallery
- $industries = get_terms('dez_gallery_industry', array(
- 'hide_empty' => false,
- ));
- ?>
- <form class="dez-gallery-filters">
- <label>
- <?php esc_html_e('Categories:', 'text-domain'); ?><br>
- <?php foreach ($categories as $category) : ?>
- <input type="checkbox" name="dez-gallery-category[]" value="<?php echo esc_attr($category->term_id); ?>"> <?php echo esc_html($category->name); ?><br>
- <?php endforeach; ?>
- </label>
- <label>
- <?php esc_html_e('Industries:', 'text-domain'); ?><br>
- <?php foreach ($industries as $industry) : ?>
- <input type="checkbox" name="dez-gallery-industry[]" value="<?php echo esc_attr($industry->term_id); ?>"> <?php echo esc_html($industry->name); ?><br>
- <?php endforeach; ?>
- </label>
- <button type="submit"><?php esc_html_e('Filter', 'text-domain'); ?></button>
- </form>
- ////<?php
- // Get the selected category and industry filters
- $category_filters = isset($_GET['dez-gallery-category']) ? array_map('intval', $_GET['dez-gallery-category']) : array();
- $industry_filters = isset($_GET['dez-gallery-industry']) ? array_map('intval', $_GET['dez-gallery-industry']) : array();
- // Setup gallery query arguments
- $gallery_args = array(
- 'post_type' => 'dez_gallery',
- 'posts_per_page' => -1,
- );
- // Add category filters to query
- if (!empty($category_filters)) {
- $gallery_args['tax_query'][] = array(
- 'taxonomy' => 'dez_gallery_category',
- 'field' => 'term_id',
- 'terms' => $category_filters,
- 'operator' => 'IN',
- );
- }
- // Add industry filters to query
- if (!empty($industry_filters)) {
- $gallery_args['tax_query'][] = array(
- 'taxonomy' => 'dez_gallery_industry',
- 'field' => 'term_id',
- 'terms' => $industry_filters,
- 'operator' => 'IN',
- );
- }
- // Get gallery items
- $gallery_query = new WP_Query($gallery_args);
- // Display gallery items
- if ($gallery_query->have_posts()) :
- ?>
- <div class="dez-gallery-items">
- <?php while ($gallery_query->have_posts()) : $gallery_query->the_post(); ?>
- <div class="dez-gallery-item">
- <?php if (has_post_thumbnail()) : ?>
- <a href="<?php the_permalink(); ?>">
- <?php the_post_thumbnail('medium'); ?>
- </a>
- <?php endif; ?>
- </div>
- <?php endwhile; ?>
- </div>
- <?php
- endif;
- // Reset post data
- wp_reset_postdata();
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement