Custom field in search form
-
Hi
I used snippets to add custom field (Radio button) to my Advert_Add form.
How can i add the values of field in the search form and result ?The page I need help with: [log in to see the link]
-
Hi,
what snippet have you used exactly? I am looking at the page you linked to and there is no Radio button in the search form?Now on this page (https://www.237marketplace.com/rechercher-une-annonce/deposer-une-annonce/) I change radio “type d’annonce” for a dropdown.
I want to add the dropdown on this search page (https://www.237marketplace.com/rechercher-une-annonce/) and add the values in the wp_query for ads
Really need help with this one @gwin plz
The Add an Ad page is https://www.237marketplace.com/rechercher-une-annonce/deposer-une-annonce/
When you add an ad using “Gratuit” radio, this should be the free mode. But i always have to moderate later to display ad @gwin@gwin I used this code https://wpadverts.com/documentation/custom-fields/
1. edit the page https://www.237marketplace.com/rechercher-une-annonce/deposer-une-annonce/ and check if you are using the shortcode
[adverts_add]with moderate=”1″ param, if you do then remove it. The free ads will not be put into moderation then.2. to insert the options in the search form you need to use the code below
add_filter( 'adverts_form_load', 'search_by_typedannonce_form_load' ); function search_by_typedannonce_form_load( $form ) { if( $form['name'] != 'search' ) { return $form; } $form['field'][] = array( "name" => "my_custom_radio", "type" => "adverts_field_select", "order" => 20, "label" => __("Type d'annonce", "adverts"), "max_choices" => 10, "options" => array( array( "value" => "Vente", "text" => "Vente" ), array( "value" => "Location", "text" => "Location" ), array( "value" => "Echange", "text" => "Echange" ), ), "meta" => array( "search_group" => "visible", "search_type" => "full" ) ); return $form; }Additionally, to search by this field you would need to add the code below in theme functions.php file as well
add_filter( 'adverts_list_query', 'search_by_typedannonce_query' ); function search_by_typedannonce_query( $args ) { if( ! adverts_request( "my_custom_radio" ) ) { return $args; } $args["meta_query"][] = array( 'key'=> "my_custom_radio", 'value'=> adverts_request( "my_custom_radio" ), 'compare'=> 'LIKE' ); return $args; }Thx so much
1 – My [adverts_add] page was by default ([adverts_add]), no moderate param2 – i used the code and the field is add correctly in the search form, but the search query doesn’t work well i think. When i check a value which doesn’t appear in no Ad, the defaults Add_list is still display, instead of a “No result” mention.
-
This reply was modified 7 years, 2 months ago by
kintango.
Can i add more than one condition “Compare” to extend the number of results? @gwin
Hi,
since the location allows multiple options selection you can try replacing the code'key'=> "my_custom_radio", 'value'=> adverts_request( "my_custom_radio" ), 'compare'=> 'LIKE'with
'key'=> "my_custom_radio", 'value'=> adverts_request( "my_custom_radio" ), 'compare'=> 'IN'If you wish to further refine the results you can add additional WP_Query params before the
return $args;line.The $args variable is basically an array that will be passed to WP_Query so you can customize it like any other WP_Query https://codex.wordpress.org/Class_Reference/WP_Query
Thanks @gwin It’s work perfectly now
-
This reply was modified 7 years, 2 months ago by
The topic ‘Custom field in search form’ is closed to new replies.