Search result is not working
-
Dear Sir,
1/ Please help me checking my site b/c wpadverts search is not working right.
When I click to “Search” button, it has no result
https://sangnhuonghieuqua.com/?advert_example=52
But when I change this link, it is working:
https://sangnhuonghieuqua.com/?advert_example=quan-10
(quan-10 is a slug of “52” category)2/ I want to add thumbnail in search result. Plese help me how to show them.
Thank you very much and I’m so sorry b/c my bad English. ??
The page I need help with: [log in to see the link]
-
Hi,
1. i understand the advert_example is a name of a custom taxonomy? If so then most likely the search https://sangnhuonghieuqua.com/?advert_example=52 is conflicting with WP router which tries to route the page to the taxonomies.It seems you are using the Custom Fields extension? If so then the easiest way to fix that would be to remove the field named advert_example from the search form then add it again with the same params but make sure to use a name different than “advert_example” for example you can use “ad_example”.
2. when you will make the changes in point #1 the search should work fine and display the results in a default WPAdverts layout with search bar and images.
Dear Greg,
I tried with your instructions but it didn’t working right. It’s not only in slugs “advert_example” but also “advert_category” error. You can see at https://sangnhuonghieuqua.com/?advert_category=19
Please help me clearly how to fix this. Thank you so much again.
Dear Sir,
I changed “advert_example” to “advert-distric” but it’s still not working:
https://sangnhuonghieuqua.com/advert-distric/quan-10
Please give me advice. Tks a lots.<?php /** Plugin Name: WPAdverts Snippets - Custom Taxonomies Version: 1.0 Author: Greg Winiarski Description: Adds custom taxonomy to [adverts_add] and displays values (as links) in Ad details page. */ add_action( "init", "custom_taxonomies_init", 50 ); add_filter( "adverts_form_load", "custom_taxonomies_form_load" ); add_filter( "adverts_list_query", "custom_taxonomies_query" ); add_action( "adverts_tpl_single_details", "custom_taxonomies_tpl_single_details" ); /** * Custom Taxonomy Init * * Registers new custom taxonomy * * @since 1.0 * @return void */ function custom_taxonomies_init() { $args = array( 'label' => __( "Qu?n, huy?n" ), 'hierarchical' => true, 'query_var' => true, 'rewrite' => array('slug' => 'advert-distric'), ); register_taxonomy( 'ad_distric', 'advert', $args ); } /** * Returns options for ad_distric field * * This function is being used when generating category field in the (for example * "post ad" form). * * @uses adverts_walk_category_dropdown_tree() * @since 1.0 * @return array */ function custom_taxonomies_options() { $args = array( 'taxonomy' => 'ad_distric', 'hierarchical' => true, 'orderby' => 'name', 'order' => 'ASC', 'hide_empty' => false, 'depth' => 0, 'selected' => 0, 'show_count' => 0, ); include_once ADVERTS_PATH . '/includes/class-walker-category-options.php'; $walker = new Adverts_Walker_Category_Options; $params = array( get_terms( 'ad_distric', $args ), 0, $args ); return call_user_func_array(array( &$walker, 'walk' ), $params ); } /** * Adds "Taxonomy Example" field into [adverts_add] form. * * @since 1.0 * @access public * @param array $form Adverts Form structure * @return array Customized form structure */ function custom_taxonomies_form_load( $form ) { global $pagenow; if( $form['name'] == "advert" && $pagenow != "post.php" ) { $form["field"][] = array( "name" => "ad_distric", "type" => "adverts_field_select", "order" => 8, "label" => __( "Qu?n, huy?n", "adverts" ), "is_required" => true, "max_choices" => 1, "options" => array(), "options_callback" => "custom_taxonomies_options", "validator" => array( array( "name" => "is_required" ), ) ); } if( $form['name'] == "search" ) { $form['field'][] = array( "name" => "ad_distric", "type" => "adverts_field_select", "order" => 20, "label" => "Qu?n, huy?n", "empty_option" => 1, "empty_option_text" => "Ch?n qu?n, huy?n...", "max_choices" => 1, "options" => array(), "options_callback" => "custom_taxonomies_options", "meta" => array( "search_group" => "visible", "search_type" => "half" ) ); } return $form; } /** * Displays selected terms on Ad details page. * * This functions is executed by adverts_tpl_single_details filter * * @since 1.0 * @access public * @param int $post_id Currently displayed post ID */ function custom_taxonomies_tpl_single_details( $post_id ) { $terms = get_the_terms( $post_id, 'ad_distric' ); ?> <?php if(! empty( $terms ) ): ?> <div class="adverts-grid-row"> <div class="adverts-grid-col adverts-col-30"> <span class="adverts-round-icon adverts-icon-wordpress"></span> <span class="adverts-row-title">Qu?n, huy?n</span> </div> <div class="adverts-grid-col adverts-col-65"> <?php foreach( $terms as $term ): ?> <a href="<?php echo esc_attr( get_term_link( $term ) ) ?>"><?php echo join( " / ", advert_category_path( $term ) ) ?></a><br/> <?php endforeach; ?> </div> </div> <?php endif; ?> <?php } /** * Adds tax_query param to WP_Query * * The tax_query is added only if it is in $_GET['advert_example'] * * @param array $args WP_Query args * @return array Modified WP_Query args */ function custom_taxonomies_query( $args ) { if( ! adverts_request( "ad_distric" ) ) { return $args; } $args["tax_query"] = array( array( 'taxonomy' => 'ad_distric', 'field' => 'term_id', 'terms' => adverts_request( "ad_distric" ), ), ); return $args; }
Hi, it still seems to be the problem i explained in the first message as you are still using the exact taxonomy names when searching.
In other words, if your SEO friendly link to a category is https://sangnhuonghieuqua.com/advert-category/sang-nhuong-clb-the-hinh, then the URL after searching should (for example) look like this https://sangnhuonghieuqua.com/?ad_category=35
If you will use a link like https://sangnhuonghieuqua.com/?advert_category=35 then it will conflict with the SEO friendly category links, this is also true for the advert_example or advert_distric taxonomies.
I would recommend taking a step back, disabling the advert_distric snippet and making it work properly for the advert_category first.
Can you let me know how do you have the category field added to the search form? If using the Custom Fields extension then can you paste a link to your search by category field configuration?
- The topic ‘Search result is not working’ is closed to new replies.