• Resolved stephanium

    (@stephanium)


    My live search only finds results in the post Content OR the Post Titles.
    If I take the post_content on the first Place in my Code (like it is now), its finding results in the Content. When I take post_title on the First Place it only searches my typed Words in the Title.
    My Question: How should I write the code if I want it to search in my post Content AND Post Titles?

    $query = "
    			SELECT
    				$wpdb->posts.ID
    			FROM
    				$wpdb->posts
    			WHERE
    				((post_content LIKE '%%%s%%') OR (post_title LIKE '%%%s%%')
    				AND post_status='publish'
    				AND post_type='".$post_type."'
    				$excludes
    				$order_results
    			LIMIT 0, %d";

Viewing 4 replies - 1 through 4 (of 4 total)
  • I’m not entirely sure how you have things setup (since there are other variables in your sql statement)… but try this:

    $query = "
    	SELECT
    		$wpdb->posts.ID
    	FROM
    		$wpdb->posts
    	WHERE
    		post_content LIKE '%s'
    	OR
    		post_title LIKE '%s'
    	AND
    		post_status='publish'
    	AND
    		post_type='".$post_type."'
    		$excludes
    		$order_results
    	LIMIT 0, %d";
    Thread Starter stephanium

    (@stephanium)

    Thanks for the reply
    But it’s still not working with your code 🙁

    With your Code it doesn’t find something in the title or Content at all.

    Thread Starter stephanium

    (@stephanium)

    Sorry I’ve got the solution now!

    There was an wrong Setting in a Plugin witch I didn’t see

    Thread Starter stephanium

    (@stephanium)

    –Topic resolved–

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Simple logic OR in $wpdb query’ is closed to new replies.