• Resolved garethf

    (@garethf)


    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

    https://www.ads-software.com/plugins/wpadverts/

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author Greg Winiarski

    (@gwin)

    The multiselect dropdown does not load properly on your site, because you have following JavaScript error (which prevents WPAdverts multi-dropdown script from executing).

    Uncaught TypeError: $(...).flexslider is not a function

    The error seems to be coming from your theme https://equity4sweat.com/wp-content/themes/shapely/js/shapely-scripts.js?ver=20160115

    Thread Starter garethf

    (@garethf)

    Thanks! Updated the functions.php for the theme and it works perfectly now – seems this was a known error.

    This also solved the problem with upload images!

    This code is not able to give me search by category

    <?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…..send to unknown url …like that

    Plugin Author Greg Winiarski

    (@gwin)

    Please be more specific, the search field does not show or WPAdverts ignores the search params? also your website URL would be helpful.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Search By Category’ is closed to new replies.