My posts have a bunch of custom fields, to help insert and display custom info easily. I am trying to build a search that would select and display posts according values of specific 2 custom fields. The first field "type" is a radio button in my wp-admin, so in database its meta value is always one word. But second field is checkboxes, so in database meta value has several words, and I need to get posts that have the one visitor selects.

What I have so far:

  1. Search form, that consists of 2 dropdowns, each for one custom field. I use it one homepage: pastebin.com/zxPuGduW
  2. A function in functions.php, to select posts according the values set in dropdowns: pastebin.com/Z6D0GM4q
  3. A results page to show the posts according selections in the dropdowns form: pastebin.com/KHK0exWn
  • 1
    What's your question exactly? Why not just use WP_Query instead of a raw SQL query?
    – Milo
    Commented Aug 24, 2013 at 16:54
  • 1
    Please edit relevant code into the question itself. A question should not be dependent upon a third party site.
    – s_ha_dum
    Commented Aug 24, 2013 at 16:55
  • Oh, sorry, the question is that it does not work... And I cannot figure it out why. I tried WP_Query way, but was not able to make it search across multiple custom fields at once. Commented Aug 24, 2013 at 16:58
  • I was not able to post code here formatted nicely, and I didn't know it is not allowed to use another site...sorry. Commented Aug 24, 2013 at 17:00
  • "it does not work" is not a question. Where/how does it fail? You need to do some of the debugging yourself. This site has perfectly adequate code formating-- look for the {} button-- though it would be nice if it had line numbers.
    – s_ha_dum
    Commented Aug 24, 2013 at 17:20

1 Answer 1


You should be able to do this with WP_Query's meta_query parameters:

$type = 'something';
$programme = 'another';

$args = array(
    'meta_query' => array(
            'key' => 'type',
            'value' => $type,
            'compare' => '='
            'key' => 'programme',
            'value' => $programme,
            'compare' => 'LIKE'
$query = new WP_Query( $args );
  • OMG, totally! Thank you so much. I am trying that right now. Will update on the results. Commented Aug 24, 2013 at 18:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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