Search By Category
-
Hi,
I’m trying to implement the ability to search by category.
I created a plugin file as follows but it displays the search field as a scrollable list – is it possible to make this a drop downm multi-select list?
<?php /* Plugin Name: E4S Plugin URI: https://www.equity4sweat.com Description: Plugin for editing content of WPAdverts plugin Author: G Fenney Version: 1.0 Author URI: https://www.equity4sweat.com */ add_filter( 'adverts_form_load', 'search_by_category_form_load' ); /** * Adds category dropdown into search form in [adverts_list]. * * @param array $form Search form scheme * @return array Customized search form scheme */ function search_by_category_form_load( $form ) { if( $form['name'] != 'search' ) { return $form; } $form['field'][] = array( "name" => "advert_category", "type" => "adverts_field_select", "order" => 20, "label" => __("Category", "adverts"), "max_choices" => 10, "options" => array(), "options_callback" => "adverts_taxonomies", "meta" => array( "search_group" => "visible", "search_type" => "full" ) ); return $form; } add_filter( 'adverts_list_query', 'search_by_category_query' ); /** * Adds tax_query param to WP_Query * * The tax_query is added only if it is in $_GET['advert_category'] * * @param array $args WP_Query args * @return array Modified WP_Query args */ function search_by_category_query( $args ) { if( ! adverts_request( "advert_category" ) ) { return $args; } $args["tax_query"] = array( array( 'taxonomy' => 'advert_category', 'field' => 'term_id', 'terms' => adverts_request( "advert_category" ), ), ); return $args; }
Please help
Viewing 4 replies - 1 through 4 (of 4 total)
Viewing 4 replies - 1 through 4 (of 4 total)
- The topic ‘Search By Category’ is closed to new replies.