Wordpress get_posts if keyword exists in title, content or tag Wordpress get_posts if keyword exists in title, content or tag wordpress wordpress

Wordpress get_posts if keyword exists in title, content or tag


you can use your own query . below is an example

$querystr="    SELECT *        FROM $wpdb->posts, $wpdb->term_relationships, $wpdb->term_taxonomy, $wpdb->terms            WHERE ($wpdb->terms.name = '$s'            OR $wpdb->posts.post_content LIKE '%$s%'        OR $wpdb->posts.post_title LIKE '%$s%')        AND $wpdb->posts.ID = $wpdb->term_relationships.object_id        AND $wpdb->term_relationships.term_taxonomy_id = $wpdb->term_taxonomy.term_taxonomy_id        AND $wpdb->term_taxonomy.term_id = $wpdb->terms.term_id        ORDER BY $wpdb->posts.post_date DESC";$pageposts = $wpdb->get_results($querystr, OBJECT_K);foreach ($pageposts as $post): setup_postdata($post);    echo the_title() . '<br /><br />';endforeach;


I have used wpdb query to fetch the result. Join the posts and taxonomy table and then get the distinct result by $search_title. Hope this will work. :)

global $wpdb;$querystr= "SELECT DISTINCT $wpdb->posts.* FROM $wpdb->posts                LEFT JOIN $wpdb->term_relationships                    ON ( $wpdb->posts.ID = $wpdb->term_relationships.object_id )                LEFT JOIN $wpdb->term_taxonomy                    ON ( $wpdb->term_relationships.term_taxonomy_id = $wpdb->term_taxonomy.term_taxonomy_id )                LEFT JOIN $wpdb->terms                    ON ( $wpdb->term_taxonomy.term_id = $wpdb->terms.term_id )                 WHERE ( $wpdb->terms.name LIKE '%$search_title%'                    OR $wpdb->posts.post_content LIKE '%$search_title%'                    OR $wpdb->posts.post_title LIKE '%$search_title%' )                    AND $wpdb->posts.post_status = 'publish'                    AND $wpdb->posts.post_type = 'product'                     ORDER BY $wpdb->posts.post_title ASC";$query_object = $wpdb->get_results($querystr);


Check out the Post Clauses filters Wordpress offers. It allows you to plug in MySQL Statements directly to the WP query.