functions.php
///////////////////////////////////////////////// // // Custom Post Type -> Exhibition // Exhibition Filters // ///////////////////////////////////////////////// function create_exhibition_post_type() { $labels = array( 'name' => esc_html__( 'Exhibitions', 'naix' ), 'singular_name' => esc_html__( 'Exhibition', 'naix' ), 'add_new_item' => esc_html__( 'Add New Exhibition', 'naix' ), ); $args = array( 'labels' => $labels, 'public' => true, 'has_archive' => true, 'rewrite' => array('slug' => 'exhibitions'), 'menu_icon' => 'dashicons-format-gallery', 'supports' => array('title','editor','thumbnail','excerpt'), 'publicly_queryable' => true, ); register_post_type('exhibition', $args); } add_action('init', 'create_exhibition_post_type'); function exhibition_filter_function(){ $args = array( 'post_type' => 'exhibition', 'posts_per_page' => 12, ); if(isset($_POST['status']) && $_POST['status'] == 'all') { $state = ''; } if(isset($_POST['status']) && $_POST['status'] == 'current') { //Current $args['meta_query'][] = array( array( 'key' => 'start_date', 'value' => date("Y-m-d"), 'compare' => '<=', 'type' => 'DATE', ), array( 'key' => 'end_date', 'value' => date("Y-m-d"), 'compare' => '>=', 'type' => 'DATE', ), ); $state = esc_html__( 'current', 'naix' ); } if(isset($_POST['status']) && $_POST['status'] == 'upcomming') { // Upcomming $args['meta_query'][] = array( array( 'key' => 'start_date', 'value' => date("Y-m-d"), 'compare' => '>', 'type' => 'DATE', ), ); $state = esc_html__( 'upcomming', 'naix' ); } if(isset($_POST['status']) && $_POST['status'] == 'past') { //Past $args['meta_query'][] = array( array( 'key' => 'end_date', 'value' => date("Y-m-d"), 'compare' => '<', 'type' => 'DATE', ), ); $state = esc_html__( 'past', 'naix' ); } if(isset($_POST['place'])) { //Location Filter $raw_values = $_POST['place']; $values = array(); // Combine 3 museums in one checkbox foreach ($raw_values as $value) { if($value == 815) { array_push($values, 101, 104, 326); } else { $values[] = $value; } } $meta_val = array('relation' => 'OR'); foreach ($values as $value) { $meta_val[] = array( 'key' => 'place', 'value' => $value, 'compare' => 'LIKE', ); $places[] = ''. get_the_title( $value ) .''; } $args['meta_query'][] = $meta_val; } $query = new WP_Query( $args ); if( $query->have_posts() ) : while( $query->have_posts() ) : $query->the_post(); get_template_part( 'template-parts/custom', 'fourcolsgrid' ); endwhile; wp_reset_postdata(); else : ?>