• Resolved larisashev

    (@larisashev)


    Hi Greg!
    I’ve added a custom field (named “ИНН” in my form) acccording to your documentation but the value of this field doesn’t get in the site search.
    Help me, please.

    • This topic was modified 6 years, 9 months ago by larisashev.

    The page I need help with: [log in to see the link]

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

    (@gwin)

    Hi, do you mean that when you enter in ИНН value “Testing” and then in [adverts_list] search for “Testing” no results are found?

    If so then i am afraid that it is not really possible to search like that out of box. The keyword field can only search in title and description.

    What you can do is add the ИНН field to the [adverts_list] form https://wpadverts.com/documentation/custom-fields-search-form/

    There also seems to be a way to modify the WP_Query object to search by both title/description and a custom field but it requires some porgramming https://wordpress.stackexchange.com/questions/78649/using-meta-query-meta-query-with-a-search-query-s

    I have never tried the solution prosed there so i cannot tell if it works, but when i will find some free time i will test it (hopefully this week).

    Thread Starter larisashev

    (@larisashev)

    thank you for the answer!
    i’ve added the ИНН field to the [adverts_list] form:

    add_filter( 'adverts_form_load', 'search_by_INN' );
    function search_by_INN( $form ) {
        
        if( $form['name'] != 'search' ) {
            return $form;
        }
        $form['field'][] = array(
            "name" => "query",
            "type" => "adverts_field_text",
            "order" => 10,
            "label" => "",
    		"placeholder" => __("ИНН ...", "adverts"),
            "meta" => array(
                "search_group" => "visible",
                "search_type" => "half" 
            )
        );
        return $form;
    }

    but i don’t understand how i can modify the code below:

    add_filter( 'adverts_list_query', 'search_by_INN_query' );
    function search_by_INN_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;
    }

    besides it looks like the search form stopped working in general https://xn—-8sbafhjd1b1adcehode7af3p.xn--p1ai/?page_id=88

    Plugin Author Greg Winiarski

    (@gwin)

    Hi, the INN you are storing in the meta fields, so your search_by_INN_query() function should look like this

    
    function search_by_INN_query( $args ) {
        if( adverts_request( "inn" ) ) {
            $args["meta_query"][] = array( 
                'key' => 'adverts_price', 
                'value' => adverts_request( 'inn' ), 
            );
        
        return $args;
    }
    

    Additionally, in the search_by_INN() function you will need to change line "name" => "query", to "name" => "inn",.

    Once you do that try refreshing the page and do a search again.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Custom Fields’ is closed to new replies.