Support Forums

The forums are closed and will be removed when we launch our new site.

Looking for support? You can access the support system via your account.

Odi

Forum Replies Created

Viewing 3 posts - 1 through 3 (of 3 total)
  • Odi in reply to:
    Get active applied filters and search keyword
    #259956

    Hi Trevor,
    Thank you for the response. The code you sent works well, however, it needs to be in the archive page itself to work, which is something I’m trying to avoid because that would mean the page has to reload to display the active filters.

    I tried to run it through AJAX once the form submits. But I’m not getting any results. (below is the function I added to functions.php) (the ajax request works fine, so the issue is with $searchandfilter).

    Is there any way to use the “$searchandfilter” class and the “current_query()” method from OUTSIDE the archive page?

    Please let me know. thank you.

    add_action( 'wp_ajax_show_active_filters',  'show_active_filters' );
    add_action( 'wp_ajax_nopriv_show_active_filters', 'show_active_filters' );
    function show_active_filters(){
        global $searchandfilter;
        $sf_current_query = $searchandfilter->get(8175)->current_query()->get_array();
        ob_start();
        
        echo '<span class="active-pill">'.$sf_current_query['_sft_contest-years']['active_terms'][0]['name'].'</span>';
    
        $ajax_filters_html .= ob_get_contents();
        ob_end_clean();
        echo json_encode(array('html'=>$ajax_filters_html));
        wp_die();
    }
    Odi in reply to:
    Get active applied filters and search keyword
    #259944

    Hi Trevor,

    I am not using a page builder or anything. I am using a CPT archive page and everything works fine. Even the results of “$searchandfilter->get(ID)->current_query()” are shown ON PAGE RELOAD which I’m trying to avoid since I want to load the results using AJAX.

    Here is a screenshot of what I’m trying to achieve along with the use case:
    https://share.getcloudapp.com/rRu7ZZzl

    – When a user selects a Year -> this would add an active filter pill with the selected year (example: 2020) – Same goes for the rest of the filters and the search input field.
    – When a user hits the X on the active filter pill, it needs to remove that from the filters and resubmits the form.

    Thank you in advance!

    Odi in reply to:
    Get active applied filters and search keyword
    #259932

    I found this class that allows to output the current filters

    <?php
    	//Get an array of objects containing data for the current search/filter
    	//replace <code>1526</code> with the ID of your search form
    	global $searchandfilter;
    	$sf_current_query = $searchandfilter->get(1526)->current_query();
    	var_dump($sf_current_query->get_array());
    ?>

    But what I’m really looking for is to dynamically display the filter terms AND search term on Submit (AJAX enabled). Also the ability to Clear those Filters / Search items one by one (X them out).

    Please let me know if this is doable?

Viewing 3 posts - 1 through 3 (of 3 total)