I had a problem creating an advanced search with a custom query and using $wpdb->get_results($query , OBJECT);
In a regular Wordpress search, when searching for xxx yyyy or searching for yyyy xxx we have the same results, which is good. But when I have to use a query to create an advanced search, then the sequence of words in the search fields is important, and then xxx yyyy or the search yyyy xxx are not the same result. I want to say with an example: I create two input fields for Title and another for Author of my messages (the author is an example only in this place - these are custom fields) I try to read these fields and search them in wordpress
<?php $t = $_REQUEST['title']; $a = $_REQUEST['author']; global $wpdb; $query = "SELECT DISTINCT wp_posts.* FROM wp_posts, wp_postmeta WHERE wp_posts.ID = wp_postmeta.post_id"; if ($t != '') { $t_sql = " AND wp_posts.post_title like '%$t%' "; } if ($a != '') { $a_sql = " AND wp_postmeta.meta_key = 'Author' AND wp_postmeta.meta_value like '%$a%' "; } $query .= $t_sql; $query .= $a_sql; $pageposts = $wpdb->get_results($query , OBJECT); global $post; if ($pageposts): foreach ($pageposts as $post): setup_postdata($post);
In your idea, what should I do?
source share