• Resolved bdd

    (@bws-online)


    I have 2 search-related questions:

    1. Is there a way to include the names of the people who posted the ads as part of the search? (Related to this, what fields ARE searched as part of search?)

    2. Is there a way to add a button to clear/reset the search? (Especially when a search returns no results, it seems like it could be more user friendly.)

    Thanks!

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

    (@gwin)

    1. you can customize the keyword search with posts_where filter for exampe, see https://wordpress.stackexchange.com/questions/224364/wp-query-search-not-taking-keywords-with-together-for-multiple-words

    2. the clear button you would need to add directly in wpadverts/templates/list.php file.

    Thread Starter bdd

    (@bws-online)

    I’m not seeing how the link you included would help me modify the existing search so that it looks at adverts_person in addition to what it’s already searching.

    I don’t see where it indicates what fields it’s searching (which seem to be just title and description). Are they being added to the visible group somewhere and that’s how it’s controlled? Or is there another place where this is set?

    Any direction you could provide would be very much appreciated.

    I see the default search form info in defaults.php:

    // Set default search form in [adverts_list] shortcode
    Adverts::instance()->set("form_search", array(
        "name" => "search",
        "action" => "",
        "field" => array(
            array(
                "name" => "query",
                "type" => "adverts_field_text",
                "label" => "",
                "order" => 10,
                "placeholder" => __("Keyword ...", "adverts"),
                "meta" => array(
                    "search_group" => "visible",
                    "search_type" => "half" 
                )
    
            ),
            array(
                "name" => "location",
                "type" => "adverts_field_text",
                "label" => "",
                "order" => 10,
                "placeholder" => __("Location ...", "adverts"),
                "meta" => array(
                    "search_group" => "visible",
                    "search_type" => "half"
                )
            )
        )
    ));

    It feels like I need to add to that a bit.

    Okay, with a little more exploration, I found your snippets for search by price, date, and category. I created a new plugin for search by name — almost there, but not quite. Can you help me with some of the key variables for this? For example, am I missing anything in this section?

    $form['field'][] = array(
            "name" => "adverts_person",
            "type" => "adverts_field_text",
            "order" => 20,
            "label" => __("Member Name"),
            "meta" => array(
                "search_group" => "visible",
                "search_type" => "half" 
            )
        );

    And are the names right in this?

    function search_by_name_query( $args ) {
        
        if( ! adverts_request( "adverts_person" ) ) {
            return $args;
        }
        
        $args["tax_query"] = array(
            array(
                'taxonomy' => 'adverts_person',
                'field'    => 'term_id',
                'terms'    => adverts_request( "adverts_person" ),
            ),
        );
        
        return $args;
    }

    The field is showing up under the Keyword… field on my page, but text typed into the field doesn’t get recognized/produce in any results. I feel like I’m close!! I don’t think I have something right to search the list of people who have ads posted.

    Thanks again.

    Plugin Author Greg Winiarski

    (@gwin)

    1. the page i linked to explains how to customize the search by keyword as from your description i understood that if an Ad is posted by “John Doe” then when searching by keyword “John Doe” you would like the Ad to be found, if you want to have a separate field for author search then the linked article will not help.

    2. the first snippet seems fine the second would need to look like this

    
    function search_by_name_query( $args ) {
        
        if( ! adverts_request( "adverts_person" ) ) {
            return $args;
        }
        
        $args["meta_query"][] = array(
            'key' => 'adverts_person',
            'value' => adverts_request( "adverts_person" ),
            'compare' => 'LIKE'
        );
        
        return $args;
    }
    

    If you would like the match to be found only when typing the exact contact name then remove the line 'compare' => 'LIKE' from above code.

    Please also make sure you have there somewhere a line

    
    add_filter( 'adverts_list_query', 'search_by_name_query' );
    
Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Search questions (names, clear/reset)’ is closed to new replies.