This website uses cookies to personalize your experience. By using this website you agree to our cookie policy.

terms filter on custom page

Home Forums Product Support Forums Ajax Search Pro for WordPress Support terms filter on custom page

Viewing 15 posts - 1 through 15 (of 29 total)
  • Author
    Posts
  • #52464
    gavriel_wtTjgavriel_wtTj
    Participant

    hi,

    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.

    #52466
    Ernest MarcinkoErnest Marcinko
    Keymaster

    Hi!

    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?

    #52467
    gavriel_wtTjgavriel_wtTj
    Participant

    its 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;

    #52468
    gavriel_wtTjgavriel_wtTj
    Participant

    and note that it’s not an archive template, these are pages

    #52474
    gavriel_wtTjgavriel_wtTj
    Participant

    any idea? 🙂

    #52475
    Ernest MarcinkoErnest Marcinko
    Keymaster

    Sure! 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 🙂

    #52476
    gavriel_wtTjgavriel_wtTj
    Participant

    ah great 🙂 thanks. looking forward to hearing back from you then!

    #52477
    Ernest MarcinkoErnest Marcinko
    Keymaster

    All 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_3 CSS 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!

    #52479
    gavriel_wtTjgavriel_wtTj
    Participant

    hi, 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

    #52480
    Ernest MarcinkoErnest Marcinko
    Keymaster

    Okay. 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.

    #52481
    gavriel_wtTjgavriel_wtTj
    Participant

    i added it to the UL and it did nothing. If i add it to the li, it triggers something only on the first item

    #52482
    Ernest MarcinkoErnest Marcinko
    Keymaster

    Okay, 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.

    #52484
    gavriel_wtTjgavriel_wtTj
    Participant

    thanks 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. Thanks

    #52485
    Ernest MarcinkoErnest Marcinko
    Keymaster

    Sure! 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.

    #52511
    gavriel_wtTjgavriel_wtTj
    Participant

    i 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

Viewing 15 posts - 1 through 15 (of 29 total)
  • You must be logged in to reply to this topic.