• Resolved andriy14

    (@andriy14)


    Hi friends!

    This plugin and its support are so awesome, so even me, a rookie in PHP, have coped with the most of functional adjusting. But there’s something I need hard and can’t handle yet.

    It’s adding ads search by price – at least in ascending and descending order, at max – plus price diapason that client specifies. I’m digging PHP and WordPress API, though it seems that that’ll take too much time for solving the issue present.

    I could thank by donating (is there the possibility to make that?). Anyway, as my website will be growing, I plan to buy ‘Maps and Locations’ add-on.

    Hope you’ll help me! Thank you, Greg and company

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

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

    (@gwin)

    Hi, you can add “Price Min” and “Price Max” fields to the [adverts_list] search bar by pasting the code below in your theme functions.php file

    // The code below you can paste in your theme functions.php or create
    // new plugin and paste the code there.
    
    add_filter( 'adverts_form_load', 'search_by_price_form_load' );
    add_filter( 'adverts_list_query', 'search_by_price_query' );
    
    /**
     * Adds price min and max fields into search form in [adverts_list].
     *
     * @param array $form Search form scheme
     * @return array Customized search form scheme
     */
    function search_by_price_form_load( $form ) {
    
        if( $form['name'] != 'search' ) {
            return $form;
        }
    
        wp_enqueue_script( 'adverts-auto-numeric' );
    
        $form['field'][] = array(
            "name" => "price_min",
            "type" => "adverts_field_text",
            "class" => "adverts-filter-money",
            "order" => 20,
            "label" => "",
            "placeholder" => "Price min.",
            "meta" => array(
                "search_group" => "visible",
                "search_type" => "half"
            )
        );
    
        $form['field'][] = array(
            "name" => "price_max",
            "type" => "adverts_field_text",
            "class" => "adverts-filter-money",
            "order" => 20,
            "label" => "",
            "placeholder" => "Price max.",
            "meta" => array(
                "search_group" => "visible",
                "search_type" => "half"
            )
        );
    
        return $form;
    }
    
    /**
     * Adds search by price params to WP_Query
     *
     * The query is modified only if $_GET['price_min'] or $_GET['price_max']
     * is greater than 0.
     *
     * @param array $args WP_Query args
     * @return array Modified WP_Query args
     */
    function search_by_price_query( $args ) {
    
        if( adverts_request( 'price_min' ) ) {
    
            $args["meta_query"][] = array(
                'key' => 'adverts_price',
                'value' => adverts_filter_money( adverts_request( 'price_min' ) ),
                'compare' => '>=',
                'type' => 'DECIMAL(12,2)'
            );
        }
    
        if( adverts_request( 'price_max' ) ) {
            $args["meta_query"][] = array(
                'key' => 'adverts_price',
                'value' => adverts_filter_money( adverts_request( 'price_max' ) ),
                'compare' => '<=',
                'type' => 'DECIMAL(12,2)'
            );
        }
    
        return $args;
    }
    Thread Starter andriy14

    (@andriy14)

    Thank you a lot! Now my thing is ready to go) Wish you the best!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Ads price search needed highly!’ is closed to new replies.