Home › Forums › Product Support Forums › Ajax Search Pro for WordPress Support › terms filter on custom page
- This topic has 28 replies, 2 voices, and was last updated 1 year, 4 months ago by
Ernest Marcinko.
-
AuthorPosts
-
January 13, 2025 at 11:01 am #52464
gavriel_wtTj
Participanthi,
we are converting certain pages and archives to php templates instead of elementor
we have created our own product loop for these pages
https://woocommerce-707975-4987928.cloudwaysapps.com/tickets/music/
here is an example of a page that i am trying to create a terms filter that will filter my products. (not the search bar content.
i went trough some documentations and tutorials of yours, but could not find anywhere to make this possible. Can you please let me know if this is possible or not with your plugin? it’s the main reason why we purchased it.
thanks in advance and i would appreciate if you can put [email protected] in copy to the responce as he is our developer.
January 13, 2025 at 11:36 am #52466Ernest Marcinko
KeymasterHi!
Sure, I will try to assist with this.
If the page is an archive page, then it’s super easy, you can enable the archive page live loader features.
If this is not an archive, then can you let me know how exactly these loops were created? Are they coded directly within the theme via WP_Query or any different solution?
January 13, 2025 at 12:07 pm #52467gavriel_wtTj
Participantits a custom loop.
we are using jetengine query builder to create the query and then this is our code in the template:if (!empty($product_ids)) {
// Convert the comma-separated product IDs into an array
$product_ids_array = explode(‘, ‘, $product_ids);// Query the products based on the retrieved IDs
$args = array(
‘post_type’ => ‘product’, // Ensure you’re querying WooCommerce products
‘post__in’ => $product_ids_array,
‘orderby’ => ‘post__in’, // Preserve the order from the JetEngine query
‘posts_per_page’ => -1, // Adjust the number of products as needed
);$product_query = new WP_Query($args);
if ($product_query->have_posts()) :
?>
<ul id=”products-grid” class=”products-grid” style=”–width: 45%;”>
<?php while ($product_query->have_posts()) : $product_query->the_post(); ?><!– Include the product-card loop template from the loops folder –>
<?php get_template_part(‘template-parts/product-loop’, ‘loop’); ?><?php endwhile; ?>
<?php wp_reset_postdata();
else :
echo ‘No products found for the selected query.’;
endif;January 13, 2025 at 12:07 pm #52468gavriel_wtTj
Participantand note that it’s not an archive template, these are pages
January 14, 2025 at 11:52 am #52474gavriel_wtTj
Participantany idea? 🙂
January 14, 2025 at 12:05 pm #52475Ernest Marcinko
KeymasterSure! No worries, I’m looking at possible solutions on our test servers that’s why I didn’t answer yet. I will let you know in an hour. Looks to be possible from what I can see for now 🙂
January 14, 2025 at 12:09 pm #52476gavriel_wtTj
Participantah great 🙂 thanks. looking forward to hearing back from you then!
January 14, 2025 at 1:12 pm #52477Ernest Marcinko
KeymasterAll right, I have a possible solution!
1. First off, you need to put a custom code snippet into the functions.php file in your theme directory:
add_filter('asp_query_is_search', function($is_search, $wp_query){ if ( isset($wp_query->query_vars) && isset($wp_query->query_vars['asp_override']) ) { return true; } return $is_search; }, 10, 2);This will listen to an additional query parameter and trigger an override to the loop when detected.
2. In your loop template replace these lines:
$args = array( 'post_type' => 'product', // Ensure you're querying WooCommerce products 'post__in' => $product_ids_array, 'orderby' => 'post__in', // Preserve the order from the JetEngine query 'posts_per_page' => -1, // Adjust the number of products as needed );with this:
if ( isset($_GET['p_asp_data']) ) { // Query arguments to signal Ajax Search Pro for override $args = array( 'post_type' => 'product', 'asp_override' => true, ); } else { // Original WP_Query arguments $args = array( 'post_type' => 'product', // Ensure you're querying WooCommerce products 'post__in' => $product_ids_array, 'orderby' => 'post__in', // Preserve the order from the JetEngine query 'posts_per_page' => -1, // Adjust the number of products as needed ); }This will trigger the signal, whenever a live search query is detected.
3. Finally, add the
asp_es_3CSS class to the the product-card loop container, like so: https://i.imgur.com/i927SBK.png
This ensures that Ajax Search Pro knows where the template is rendered so the replacement is made correctly.That’s it, this should do the trick!
January 14, 2025 at 1:32 pm #52479gavriel_wtTj
Participanthi, first of all, thanks alot for the support
i implemented all 3 steps but allas its still not working
https://woocommerce-707975-4987928.cloudwaysapps.com/tickets/music/nothing happens when filtering
January 14, 2025 at 1:46 pm #52480Ernest Marcinko
KeymasterOkay. I see the request is started, but the render does not trigger.
Can you please also add this class to the loop container:
elementor-widget-container
That may trick the script to think it’s in an Elementor container. Hopefully this will change something.January 14, 2025 at 1:54 pm #52481gavriel_wtTj
Participanti added it to the UL and it did nothing. If i add it to the li, it triggers something only on the first item
January 14, 2025 at 2:00 pm #52482Ernest Marcinko
KeymasterOkay, I probably know why.
Can you please add a div container around the UL with class “asp_es_3” and on the UL use only “elementor-widget-container”, like so: https://i.imgur.com/BXciwWg.png
If you want, I can do direct debugging and even code change on the plugin if needed. In that case feel free to add temporary FTP and back-end access and I will do it for you.
January 14, 2025 at 3:21 pm #52484gavriel_wtTj
Participantthanks alot.
i just made the changes and now it does filter, but breaks the main query.
Im trying a couple of things with custom code and if i dont manage I would really appreciate your assistance. ThanksJanuary 14, 2025 at 3:26 pm #52485Ernest Marcinko
KeymasterSure! It’s getting super close.
I suspect the search may not be configured correctly here. I’m seeing results as product categories as well, which is a problem.
Can you please make sure, that on the search settings there are no taxonomy terms selected as results, as well as the products are the only post types selected.
That should very likely change the output.January 16, 2025 at 4:03 pm #52511gavriel_wtTj
Participanti think we will be creating our own filter for this as there is alot of customization that we need.
I haev another question: on the homepage im using the live search. Is there any option or hook to only include products that have a timestamp metafield in the future?
In my products i have a metafield expiration_date which is saved as timestamp. I would like to only return items that have this date in the future.thanks
-
AuthorPosts
- You must be logged in to reply to this topic.