Created
October 7, 2015 14:28
-
-
Save cdmz/458d996287dc217a8cb8 to your computer and use it in GitHub Desktop.
search post like title wordpress
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
add_filter( 'posts_where', 'like_title', 10, 2 ); | |
function like_title( $where, &$wp_query ) { | |
global $wpdb; | |
if ( $title = $wp_query->get( 'title' ) ) { | |
$where .= ' AND ' . $wpdb->posts . '.post_title LIKE \'%' . esc_sql( $wpdb->esc_like( $title ) ) . '%\''; | |
} | |
return $where; | |
} | |
$search_query = array( | |
'post_type'=> array( | |
'post'), | |
'title' => 'Thinkers50', | |
'posts_per_page'=> 9, | |
); | |
$wp_query = new WP_Query($search_query); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
If the post_title is "search post like title wordpress" and user query is "wordpress post search" it will not found Because it will search for the exact match of 'wordpress post search' instead searching word one by one