I have elaborate search functionality on one of my sites, it is using a custom WP_Query that will allow for an ‘AND’ & ‘OR’ relation between the users selections. It will then generate the result and overwrite the existing products in the product list. This is all being done using AJAX and a function within […]
- Tags ', 'fields' => 'ids', 'Jason', 'load_products_by_ajax_callback'); // END PAGINATION AJAX FUNCTION Things you can assume: The variables passed are correct, 'load_products_by_ajax_callback'); add_action('wp_ajax_nopriv_load_products_by_ajax', 'offset' => $offsetcalc, 'orderby' => 'menu_order', 'page' => $paged, 'post_status' => 'publish', 'posts_per_page' => $display_count, 'productloop' ); endwhile; echo ''; woocommerce_product_loop_end(); else : echo '<div clas, 'slug' => $cats, 'slug' => $tags, 'tax_query' => array() ); // Parse the search tags/categories list into an array. $tags = strlen( $search_, "relation"]], ) ); if ( $ids && ! is_wp_error( $ids ) ) : $term_ids = array_merge( $term_ids, $ids ); endif; endif; $_filter = true; // this (private) variable is used with the closure below add_filter( 'posts_cla, $ids ); endif; endif; if ( ! empty( $cats ) ) : $ids = get_terms( array( 'taxonomy' => 'product_cat', $like ); } if ( ! empty( $term_ids ) ) { $tr = uniqid( 'tr_' ); $ids, $order = " ASC ", $search_term, $term_ids ) ); $relation = ( 'AND' === $relation ? 'AND' : 'OR' ); $where = $where ? "($where) $relati, $term_ids ) { if ( $_filter ) { global $wpdb; $where = ''; if ( $search_term ) {, a category, a tag). The 'OR' relation always works, array_map( 'intval', but only while the RELATION is set to 'AND' before they then submit their search, category: '', function ( $clauses ) use ( &$_filter, I have elaborate search functionality on one of my sites, I require someone to help me doctor it so that the functionality works for when the user populates: Just the search term Just the category, if only one, if only one or two of the the options (search term, including if it has multiple of one criteria as can be found within the category and tag options the user chooses from. Leaving the 'OR' rela, it is using a custom WP_Query that will allow for an 'AND' & 'OR' relation between the users selections. It will then generate the result and, it will successfully run the search and return the desired products if each of the options are populated individually (the user only puts in, NOT FOR ALL THREE. Can anyone figure out why this doesn't work for the relation 'AND' and all three search parameters are chosen by the user, please refine your parameters!'; endif; $product_loop_count = $the_query->found_posts; echo '<div class="product-list-cou, requesting the filtered products? This is the function, tag) are selected, tag) are selected. The 'AND' relation always works, the products selected must apply to all of the selections made, to avoid issues with other // WP_Query calls. $_filter = false; if ( $the_query->have_posts() ) : woocommerce_product_l, two or all three or the options (search term, we write our own custom SQL for searching // in the post title only. We also don't use the tax_query parameter (anymore). $term_ids =