CCCPaste

Exclude Search Post by Permalink / URL

/* Exclude Search Post for ajax search */
function custom_search_post( $statement ) {
	/* List Post by Permalink */
	$list_post = array( 'http://localhost/wordpress2/hello-world/', 'http://localhost/wordpress2/shadow-tactics-blades-of-the-shogun-review/' );

	foreach( $list_post as $key => $value ) {
		$list_post[$key] = (string) url_to_postid( $value );
	}

	$statement['post__not_in'] = $list_post;

	return $statement;
}
add_filter( 'jnews_live_search_args', 'custom_search_post' );

/* Exclude Search Post */
function wpb_modify_search_query( $query ) {
    global $wp_the_query;
    if( $query === $wp_the_query && $query->is_search() ) {
		/* List Post by Permalink */
		$list_post = array( 'http://localhost/wordpress2/hello-world/', 'http://localhost/wordpress2/shadow-tactics-blades-of-the-shogun-review/' );

		foreach( $list_post as $key => $value ) {
			$list_post[$key] = (string) url_to_postid( $value );
		}

        $query->set( 'post__not_in', $list_post );
    }
}
add_action( 'pre_get_posts', 'wpb_modify_search_query' );