I want to modify wp_ajax_find_posts function. It receives search string from find-posts form and delivers search results by ajax. Part of the function looks like this:
function wp_ajax_find_posts() {
global $wpdb;
check_ajax_referer( 'find-posts' );
// ........
$search .= " OR ($wpdb->posts.post_title LIKE '%{$term}%') OR ($wpdb->posts.post_content LIKE '%{$term}%')";
$posts = $wpdb->get_results( "SELECT ID, post_title, post_status, post_date FROM $wpdb->posts WHERE post_type = '$what' AND post_status IN ('draft', 'publish') AND ($search) ORDER BY post_date_gmt DESC LIMIT 50" );
$html = //......
$x = new WP_Ajax_Response();
$x->add( array(
'what' => $what,
'data' => $html
));
$x->send();
}
add_action( 'wp_ajax_find_posts', 'wp_ajax_find_posts,1)
I want to modify the line $post to add post_author to the querry in order to limit the results within current loggin user. I would like to learn how to hook up with this wp_ajax_find_post function to let it accept my modified $post. Do I have to do remove_action and add_action to make completely rewrite of the above funtion?
You can jump in front of an AJAX hook by specifying a higher priority (i.e. lower number), like this:
NB: works because 0 < 1
I’ve posted the code for alphabetical title/content search here: SQL query not working in alphabetical post title/content search
Now you need the author as the currently logged in user. So modify the function to include this:
Let me know if it works!