Custom Fields In search Form
-
Hi Greg,
This is the code I have used for adding custom field drop down in search form.
Still having minor issues.add_filter( 'adverts_form_load', 'search_by_custom_fields_form_load' ); function search_by_custom_fields_form_load( $form ) { if( $form['name'] != 'search' ) { return $form; } $form['field'][] = array( "name" => "my_custom_fabric", "type" => "adverts_field_select", "order" => 20, "label" => "Fabric", "max_choices" => 4, "options" => array( array("value"=>"Silk", "text"=>"Silk"), array("value"=>"Cotton", "text"=>"Cotton"), array("value"=>"Woolen", "text"=>"Woolen"), ) ); add_action( "wp_footer", "search_by_custom_fields_footer" ); return $form; } add_filter( 'adverts_list_query', 'search_by_custom_fields' ); function search_by_custom_fields( $args ) { $cz = array("my_custom_fabric"); // <- more fields here foreach($cz as $name) { if( ! adverts_request( $name ) ) { continue; } if( ! isset( $args["meta_query"] ) ) { $args["meta_query"] = array(); } $args['meta_query'][] = array( 'key' => $name, 'value' => adverts_request( $name ), ); } return $args; } function search_by_custom_fields_footer() { ?> <style type="text/css"> .advert-input.advert-input-type-full { width: 100% !important; margin: 1em 0 0 0 !important; } </style> <?php }
Display of the custom field in the form happens. However,
– It is treated like hidden (I get the filter icon, beside search icon)
– The half & full option doesn’t work
– The Box comes below category box & not beside the category box.
– The new box is slightly smaller than category search box.
Also, upon inserting meta – visible/half code, the site crashes.Many thanks for your help.
Regards,
Viewing 4 replies - 1 through 4 (of 4 total)
Viewing 4 replies - 1 through 4 (of 4 total)
- The topic ‘Custom Fields In search Form’ is closed to new replies.