Add AJAX text search for custom post type
-
Hi,
I currently have category filtering correctly with my custom post type. The code I I have for this to work is
function video_filter_function(){ if (!check_ajax_referer( 'my_nonce' )){ wp_die(); }else{ $args = array( 'orderby' => 'date', // we will sort posts by date 'order' => $_POST['date'], // ASC или DESC 'tax_query' => array( array( 'taxonomy' => 'category', 'field' => 'id', 'terms' => $_POST['categoryfilter'] )), 'post_type' => 'videos', ); $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(); die(); } } add_action('wp_ajax_myfilter', 'video_filter_function'); add_action('wp_ajax_nopriv_myfilter', 'video_filter_function');
So I added
if( isset( $_POST['description'] ) ) $args = array( 'post_type' => 'videos', 'meta_key' => 'video_description', 'meta_value' => $_POST['description'] );
Which I was hoping would compliment the original function so they can search by category dropdown or a search input for the description.
But nothing is coming up for the search results now.
The page I need help with: [log in to see the link]
Viewing 11 replies - 1 through 11 (of 11 total)
Viewing 11 replies - 1 through 11 (of 11 total)
- The topic ‘Add AJAX text search for custom post type’ is closed to new replies.