From b38b8221059530ed439713f329380833f33faceb Mon Sep 17 00:00:00 2001 From: Salman Date: Tue, 17 Feb 2015 13:46:27 -0500 Subject: [PATCH] Modify News Archive search Search post title and content --- functions.php | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/functions.php b/functions.php index 937df29..8c1f99b 100644 --- a/functions.php +++ b/functions.php @@ -386,18 +386,15 @@ function prefix_ajax_clas_cat_posts() { //Retieves posts of a specific category die(); } - add_action( 'wp_ajax_clas_search_archive', 'prefix_ajax_clas_search_archive' ); add_action('wp_ajax_nopriv_clas_search_archive', 'prefix_ajax_clas_search_archive'); function prefix_ajax_clas_search_archive() { //Retieves posts of a specific category or tag, using cat/tag id $search = $_POST['search']; - - global $wpdb; - $results = $wpdb->get_col( $wpdb->prepare("SELECT ID FROM $wpdb->posts WHERE post_status = 'publish' AND post_title LIKE %s;", '%' . $wpdb->esc_like($search) . '%') ); - $archiveQuery = new WP_Query( 'category_name=archive&fields=ids' ); + + $archiveQuery = new WP_Query( 'category_name=archive&fields=ids&s='.$search.'' ); $archivePosts = $archiveQuery->get_posts(); $object = new stdClass(); - foreach( $results as $k=>$id ){ + foreach( $archivePosts as $k=>$id ){ if( in_array($id, $archivePosts) ){ $link = get_permalink($id); $title = get_the_title($id);