Home › Forums › WoodMart support forum › Ampersand character
Ampersand character
- This topic has 9 replies, 2 voices, and was last updated 4 years, 9 months ago by Aizaz Imtiaz Awan.
-
AuthorPosts
-
January 22, 2020 at 7:04 pm #169283
flasharoooParticipantHi we have a few products within the store however when we users search for products with ampersand character “&” it will return as following”
Let say products is called M&M: When typed in the search it will auto complete to M&M
Should the user proceed to type the full product name as sush M&M Tshirt it will return as NO PRODUCT Found.Can you kindly help?
January 22, 2020 at 7:10 pm #169284
flasharoooParticipantI found a temp solution to the issue by adding the code you suggest on similar post, sorry my bad i didn’t look it up before as i was tired of trying to get to the bottom of it;
However the issue only fixes the part when the product name appears as such ” M&M ”
it however does not fix the issue when you type the following letter and the search results returns with “NO PRODUCTS FOUND”Thank you.
January 23, 2020 at 6:16 am #169340
Aizaz Imtiaz AwanKeymasterHello,
First of all thanks for choosing our Theme, we are glad to be you in WoodMart WordPress family
:-)
.Please share some relevant screenshots by pointing out the specific search and the URL of the
website. Also provide the code you added in your site , So I can check it out and help you accordingly.Best Regards.
January 23, 2020 at 6:56 am #169343
flasharoooParticipant<blockquote
function woodmart_ajax_suggestions() {
$allowed_types = array( ‘post’, ‘product’, ‘portfolio’ );
$post_type = ‘product’;if ( apply_filters( ‘woodmart_search_by_sku’, woodmart_get_opt( ‘search_by_sku’ ) ) && woodmart_woocommerce_installed() ) {
add_filter( ‘posts_search’, ‘woodmart_product_ajax_search_sku’, 10 );
}$query_args = array(
‘posts_per_page’ => 5,
‘post_status’ => ‘publish’,
‘post_type’ => $post_type,
‘no_found_rows’ => 1,
);if ( ! empty( $_REQUEST[‘post_type’] ) && in_array( $_REQUEST[‘post_type’], $allowed_types ) ) {
$post_type = strip_tags( $_REQUEST[‘post_type’] );
$query_args[‘post_type’] = $post_type;
}if ( $post_type == ‘product’ && woodmart_woocommerce_installed() ) {
$product_visibility_term_ids = wc_get_product_visibility_term_ids();
$query_args[‘tax_query’][] = array(
‘taxonomy’ => ‘product_visibility’,
‘field’ => ‘term_taxonomy_id’,
‘terms’ => $product_visibility_term_ids[‘exclude-from-search’],
‘operator’ => ‘NOT IN’,
);if ( ! empty( $_REQUEST[‘product_cat’] ) ) {
$query_args[‘product_cat’] = strip_tags( $_REQUEST[‘product_cat’] );
}
}if ( ‘yes’ === get_option( ‘woocommerce_hide_out_of_stock_items’ ) ) {
$query_args[‘meta_query’][] = array( ‘key’ => ‘_stock_status’, ‘value’ => ‘outofstock’, ‘compare’ => ‘NOT IN’ );
}if ( ! empty( $_REQUEST[‘query’] ) ) {
$query_args[‘s’] = sanitize_text_field( $_REQUEST[‘query’] );
}if ( ! empty( $_REQUEST[‘number’] ) ) {
$query_args[‘posts_per_page’] = (int) $_REQUEST[‘number’];
}$results = new WP_Query( apply_filters( ‘woodmart_ajax_get_results’, $query_args ) );
$suggestions = array();
if ( $results->have_posts() ) {
if ( $post_type == ‘product’ && woodmart_woocommerce_installed() ) {
$factory = new WC_Product_Factory();
}while ( $results->have_posts() ) {
$results->the_post();if ( $post_type == ‘product’ && woodmart_woocommerce_installed() ) {
$product = $factory->get_product( get_the_ID() );$suggestions[] = array(
‘value’ => html_entity_decode( get_the_title() ),
‘permalink’ => get_the_permalink(),
‘price’ => $product->get_price_html(),
‘thumbnail’ => $product->get_image(),
);
} else {
$suggestions[] = array(
‘value’ => html_entity_decode( get_the_title() ),
‘permalink’ => get_the_permalink(),
‘thumbnail’ => get_the_post_thumbnail( null, ‘medium’, ” ),
);
}
}wp_reset_postdata();
} else {
$suggestions[] = array(
‘value’ => ( $post_type == ‘product’ ) ? esc_html__( ‘No products found’, ‘woodmart’ ) : esc_html__( ‘No posts found’, ‘woodmart’ ),
‘no_found’ => true,
‘permalink’ => ”
);
}echo json_encode( array(
‘suggestions’ => $suggestions
) );die();
}add_action( ‘wp_ajax_woodmart_ajax_search’, ‘woodmart_ajax_suggestions’, 10 );
add_action( ‘wp_ajax_nopriv_woodmart_ajax_search’, ‘woodmart_ajax_suggestions’, 10 );Attachments:
You must be logged in to view attached files.January 23, 2020 at 6:57 am #169346
flasharoooParticipantWhen you enter the full query in this case N&M it returns with the below screenshot.
Attachments:
You must be logged in to view attached files.January 23, 2020 at 12:46 pm #169412
Aizaz Imtiaz AwanKeymasterHello,
I saw that code which you shared. What if you do not add that code? Have it display the result for N&D if that code excluded. Exclude that code and check the results for “N&D” once.
Best Regards.
January 23, 2020 at 4:26 pm #169451
flasharoooParticipantAs i said if i do not add that code when i type N& without the D it shows up as Namp& but as soon as i type the following letter in this case D it get “NO PRODUCT FOUND”
I guess you didn’t even read my first message, any way i will attach a screenshot for you so you can see what happens when i remove that code.
Any ways screen shots attached.
Attachments:
You must be logged in to view attached files.January 24, 2020 at 5:48 am #169533
Aizaz Imtiaz AwanKeymasterHello,
I have already read your first message, I thought when you did not include that code then it might works but as you said it add the “amp” before the “&”, kindly deactivate all of your third party plugins and then check back after clearing your site and browser cache.
In case if it is still not fixed then remain the plugins as disable and provide me admin login details.
Best Regards.
January 24, 2020 at 6:47 pm #169691
flasharoooParticipantI never said it add it before see the original message read it again if you have to !
Let say products is called M&M: When typed in the search it will auto complete to M&M
Should the user proceed to type the full product name as sush M&M Tshirt it will return as NO PRODUCT Found.January 25, 2020 at 7:14 am #169736
Aizaz Imtiaz AwanKeymasterHello,
Could you please deactivate all the third party plugins and clear the cache then check back.
In case if it is still not fixed then remain the plugins as disable and provide me admin login details so I can check and help you out accordingly.Best Regards.
-
AuthorPosts
Tagged: special characters
- You must be logged in to create new topics. Login / Register