Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- function video_filter_function() {
- check_ajax_referer( 'my_nonce' );
- $date = sanitize_text_field( $_POST['date'] );
- $date = ( $date === 'ASC' ) ? 'ASC' : 'DESC'; // Make sure it's a valida date
- $args = array(
- 'post_type' => 'videos',
- 'orderby' => 'date',
- 'order' => $date,
- );
- // Add to query only if it's not empty
- if ( ! empty( $_POST['categoryfilter'] ) ) {
- $categoryfilter = sanitize_text_field( $_POST['categoryfilter'] );
- $args['tax_query'] = array(
- array(
- 'taxonomy' => 'category',
- 'field' => 'id',
- 'terms' => $categoryfilter,
- ),
- );
- }
- // Add to query only if it's not empty
- if ( ! empty( $_POST['description'] ) ) {
- $description = sanitize_text_field( $_POST['description'] );
- $args['meta_query'] = array(
- array(
- 'key' => 'video_description',
- 'value' => $description,
- 'compare' => 'LIKE',
- ),
- );
- }
- $query = new WP_Query( $args );
- if ( $query->have_posts() ) :
- while( $query->have_posts() ) : $query->the_post();
- ?>
- <div class="video-grid-item">
- <h2> <?php the_field('video_title'); ?></h2>
- <p> <?php the_field('video_description'); ?></p>
- <iframe src="https://player.vimeo.com/video/<?php the_field( 'vimeo' ); ?>" width="640" height="640" frameborder="0" webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe>
- </div>
- <?php
- endwhile;
- wp_reset_postdata();
- else :
- echo 'No posts found';
- endif;
- die; // Search for wp_send_json() to check how to use the JSON away
- }
- add_action( 'wp_ajax_myfilter', 'video_filter_function' );
- add_action( 'wp_ajax_nopriv_myfilter', 'video_filter_function' );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement