Skip to content
This repository has been archived by the owner. It is now read-only.

Commit

Permalink
Browse files Browse the repository at this point in the history
Modify News Archive search
Search post title and content
  • Loading branch information
szk11001 committed Feb 17, 2015
1 parent 0c731b0 commit b38b822
Showing 1 changed file with 3 additions and 6 deletions.
9 changes: 3 additions & 6 deletions functions.php
Expand Up @@ -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);
Expand Down

0 comments on commit b38b822

Please sign in to comment.