Viewing 1 replies (of 1 total)
  • Plugin Support fesupportteam

    (@fesupportteam)

    Hi @c3idesign

    Thank you for your interest in the Filter Everything plugin.

    You can access the “filter set” setting and select “more options” on the required filter to choose the “sort option” within the additional options that open.

    Or use this code example to sort them manually, but you need to have some PHP knowledge:

    add_filter('wpc_terms_before_display', 'wpc_sort_terms_as_needed', 10, 2);
    function wpc_sort_terms_as_needed($terms, $filter){
        // pa_color - is desired taxonomy
        if ($filter['e_name'] === 'pa_color') {
            // Define the custom sorting order
            $customOrder = array(
                'red',
                'blue',
                'green',
            'purple'
            );
    
            // Create an associative array to store term objects
            $termMap = array();
    
            // Populate the term map
            foreach ($terms as $term) {
                $termMap[$term->slug] = $term;
            }
    
            // Sort the terms based on the custom order
            $sortedTerms = array();
            foreach ($customOrder as $slug) {
                if (isset($termMap[$slug])) {
                    $sortedTerms[] = $termMap[$slug];
                    unset($termMap[$slug]);
                }
            }
    
            // Add any remaining terms to the sorted array
            foreach ($termMap as $term) {
                $sortedTerms[] = $term;
            }
    
            return $sortedTerms;
        }
    
        return $terms;
    }

    and this is the results –?https://prnt.sc/pYxJUGe6tXVM

    Best Regards – Victor

Viewing 1 replies (of 1 total)
  • The topic ‘display order of filters’ is closed to new replies.