0

In posts there is in custom field named "color". I have custom search page template, and I would like to show search results only from that one custom field. How to limit search to look just in one custom field inside posts?

  • What have you coded so far? – Brad Dalton Aug 1 '15 at 9:26
  • I use code from adambalee.com/… in my function.php. It works fine, but with that code every search request (on both standard and my custom search template) include results from all custom fields. And I would like to allow search of just one custom field and on kust my custom template. – Advanced SEO Aug 1 '15 at 9:35
0

Assuming you are using post_meta this should help::

$color = 'red';
$the_query = new WP_Query(array( 'meta_key' => 'color', 'meta_value' => $color ));
  • I am not sure if you understand me. To get search results WP by default look in title and content of posts for search term, but not in custom fields. I would like to make WP to look just in one custom field, "color". So, if someone search for "red" or "blue" or anything I would like to WP get posts which have that search term in custom field "color", not to get posts which may have that in title or content or in any other custom fields. – Advanced SEO Aug 1 '15 at 15:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.