I made a small adjustment to your code, because with the search results I got posts which are not published and got all post types, so I changed this:
add_action( 'wp_ajax_search_posts', 'mpo_search_posts' );
function mpo_search_posts() {
$_POST = array_map( 'stripslashes_deep', $_POST );
$search_str = $_POST['search_str'];
$args = array('s' => $search_str);
require_once ('show_posts.php');
exit;
}
To this:
add_action( 'wp_ajax_search_posts', 'mpo_search_posts' );
function mpo_search_posts() {
$_POST = array_map( 'stripslashes_deep', $_POST );
$search_str = $_POST['search_str'];
$args = array('s' => $search_str, 'post_type' => 'post', 'post_status' => 'publish');
require_once ('show_posts.php');
exit;
}
[Moderator Note: Please post code or markup snippets between backticks or use the code button.]
Cheers,
Jeroen