WordPress.org

Ready to get started?Download WordPress

Forums

using meta_query to query a custom field using OR (2 posts)

  1. slee
    Member
    Posted 3 years ago #

    I wouldlike to run the folowing but also have it retun a post if the job refernce maches the keyword search using OR but i cannot get it to work:

    if($jobtype != '') $filtertype[] =  array('taxonomy' => 'jobtype','terms' => $jobtype,'field' => 'slug');
    
    		if($location != '') $filters[] = array('key' => '_job_location','compare' => 'LIKE','value' => $location);
    		if($industry != '') $filters[] = array('key' => '_job_industry','compare' => 'LIKE','value' => $industry);
    
    		if($salary_per != '' && $salary_per != 'all') $filters[] = array('key' => '_job_salary_per','compare' => 'LIKE', 'value' => $salary_per);
    		if($salary_from != '') $filters[] = array('key' => '_job_salary_from','compare' => '>=','value' => $salary_from, 'type' => 'NUMERIC');
    		if($salary_to != '') $filters[] = array('key' => '_job_salary_to','compare' => '<=','value' => $salary_to, 'type' => 'NUMERIC');
    
    	    if($kewords != '') $filters['relation'] = 'OR';
    		if($kewords != '') $filters[] = array('key' => '_job_ref','compare' => 'LIKE', 'value' => $kewords);
    
    		$args = array(
          'post_type' => $post_type,
          //"$tax" => $tax_term->slug,
          'post_status' => 'publish',
          'posts_per_page' => $postperpage,
    	  'orderby' => 'date',
    	  'paged' => $paged,
    	  'order' => $order,
          'meta_query' => $filters,
    	  'tax_query' => $filtertype,
          's' => $kewords);

    THis works if i search for a word in the content of anythihg but if i type in a job reference it doesn bring back any posts. I assume it is not searchign in the custom field _job_ref.

    How can i enable it to search in the custom field as well?

    This is the parts i added of the custom field:

    if($kewords != '') $filters['relation'] = 'OR';
    		if($kewords != '') $filters[] = array('key' => '_job_ref','compare' => 'LIKE', 'value' => $kewords);
  2. slee
    Member
    Posted 3 years ago #

    |It seems it is because I am using the 's' to search as well tat it stops the custom field search. if i remove the 's' => $kewords from the $args then it works but then obviously doesnt search the titels or content.

    How can I have both together?

Topic Closed

This topic has been closed to new replies.

About this Topic