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

Modify News Archive search #2

Merged
merged 1 commit into from Feb 18, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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