Custom Fields Search
-
Is it possible to write a search that asks for various different Meta_Keys?
I have posts with multiple custom field entries.
Lets say a user wants to search for posts where I was reading a specific book (entered in the custom field) and only display the ones where I was happy when posting (another custom field).
More Background:
I figured out how to modify the search form. I entered all the inputs just to test. Then when you set the form action to home and request the variables you just set, you can call them (did a few echos to test. said “you serached for $var1 $var2, etc)
Got it hooked up, but it doesn’t work when I go trying to define the same thing over and over.
Any suggestions on an approach here?
<?PHP $candy = $_REQUEST['candy'] ; $mood = $_REQUEST['mood'] ; $booktype = $_REQUEST['booktype'] ; $bookpgs = $_REQUEST['bookpgs'] ; ?> <?php $querystr = " SELECT wposts.* FROM $wpdb->posts wposts, $wpdb->postmeta wpostmeta WHERE wposts.ID = wpostmeta.post_id AND wpostmeta.meta_key = 'candy' AND wpostmeta.meta_value = '$candy' AND wpostmeta.meta_key = 'mood' AND wpostmeta.meta_value = '$mood' AND wpostmeta.meta_key = 'booktype' AND wpostmeta.meta_value = '$booktype' AND wpostmeta.meta_key = 'bookpgs' AND wpostmeta.meta_value = '$bookpgs' AND wposts.post_status = 'publish' AND wposts.post_type = 'post' ORDER BY wposts.post_date DESC "; $pageposts = $wpdb->get_results($querystr, OBJECT); ?>
Thanks ??
- The topic ‘Custom Fields Search’ is closed to new replies.