Create a category search within a specific custom field
-
I have a custom field called ‘state’ and I have created a page that displays posts within a particular state. I have created a search form for categories, but I can’t figure out how to get it to search within the current pages posts (which would be posts for just one state).
I know there are many plugins to do searches, but I am trying to get away from plugins and teach myself a bit more coding. This is where I’m at:
<form name="search" action="<?php bloginfo('url'); ?>" method="get"> <fieldset> <select name="category_name"> <?php // generate list of categories $categories = get_categories(); foreach ($categories as $category) { echo '<option value="', $category->slug, '">', $category->name, "</option>\n"; } ?> </select> <input type="submit" value="search" /> </fieldset> </form>
What it’s doing is only searching the categories and that part is working great. Can anyone steer me in the right direction of a tutorial or how to only search within posts that are currently on the page, which would be posts equal to a certain custom field. That query is done like this:
// args $args = array( 'numberposts' => -1, 'post_type' => 'post', 'meta_key' => 'state', 'meta_value' => 'Georgia' ); // query $the_query = new WP_Query( '$args&meta_key=city&orderby=meta_value&order=ASC' );
Thanks in advance for any assistance,
- The topic ‘Create a category search within a specific custom field’ is closed to new replies.