I spent nearly 24 hours trying to find a solution for this issue. I'm trying to search for posts using WP_Query but it never gives a result if I don't search by the exact post title which is so unlogical to me!; I've tried all possible and logical WP_Query's arguments but still not working...
For example, I've published post, titled with (Hello and welcome!), If I search for the exact title yes I will get it, but if I change Welcome to delcome it doesn't work !! I tried to use spaces and pluses and all search cases but didn't work too ...
you can see in the below code, that I've searched by category ID which should make it closer but that didn't work too! ...
Here's my code:
$term = term_exists( 'Uncategorized', 'category' );
if ( $term !== 0 && $term !== null ) {
//echo $term['term_id'];
$args = array(
's' => 'Hello+and+delcome!',
'cat' => $term['term_id'],
'posts_per_page' => 1,
'orderby' => 'title',
'compare' => 'LIKE',
'exact' => false
);
$the_query = new WP_Query( $args );
while ( $the_query->have_posts() ) : $the_query->the_post();
the_title();
endwhile;
wp_reset_postdata();
}