Add custom field to search array?

I am using a certain theme for my wordpress website, which has created its own search widget. This widget allows me to do a txt search and search through categories. I would really like, however, to add an extra search dropdown that populates the values from a certain custom field, called ‘type’.

So to be clear…, in WP i have a custom post type. Posts in this custom post type are categorized through custom taxonomies. Now i have a search widget that allows me to search, on txt + custom taxonomies, through the posts within the custom post type. I have however also created a custom field ‘type’, which assigns ‘asked’ or ‘offered’ to a (custom) post. I would like to populate a dropdown in the current search widget with this custom field ‘type’ so that people can select a certain ‘type’ of post to perform the search in.

Read More

I hope my request is clear, sorry if my english is off sometimes (do my best:))

The code i have for the search widget can be found below:

// widget to show the search widget

function cp_ad_search_widget() {

    global $cp_options;



    $args = array(

        'show_option_all' => __( 'All Categories', APP_TD ),

        'hierarchical' => $cp_options->cat_hierarchy,

        'hide_empty' => $cp_options->cat_hide_empty,

        'depth' => $cp_options->search_depth,

        'show_count' => $cp_options->cat_count,

        'pad_counts' => $cp_options->cat_count,

        'orderby' => 'name',

        'title_li' => '',

        'use_desc_for_title' => 1,

        'name' => 'scat',

        'selected' => cp_get_search_catid(),

        'taxonomy' => APP_TAX_CAT,

    );

    $args = apply_filters( 'cp_dropdown_search_widget_args', $args );

?>



    <div class="recordfromblog">



        <form action="<?php echo home_url( '/' ); ?>" method="get" id="searchform" class="form_search">



            <input name="s" type="text" id="s" class="editbox_search" <?php if(get_search_query()) { echo 'value="'.trim(strip_tags(esc_attr(get_search_query()))).'"'; } else { ?> value="<?php _e( 'What are you looking for?', APP_TD ); ?>" onfocus="if (this.value == '<?php _e( 'What are you looking for?', APP_TD ); ?>') {this.value = '';}" onblur="if (this.value == '') {this.value = '<?php _e( 'What are you looking for?', APP_TD ); ?>';}" <?php } ?> />



            <?php wp_dropdown_categories( $args ); ?>

            <div class="pad5"></div>

            <input type="submit" class="btn_orange" value="<?php _e( 'Search', APP_TD ); ?>" title="<?php _e( 'Search', APP_TD ); ?>" id="go" name="sa" />

        </form>



    </div><!-- /recordfromblog -->        



<?php

}
?>

Any help will be greatly appreciated!
Thanks, Robbert

Related posts

Leave a Reply