• Hi, on product category of Woocommerce with Polylang not working.
    You are checking over func get_current_term in wp_query only first tax.

    [tax_query] => WP_Tax_Query Object
    (
    [queries] => Array
    (
    [0] => Array
    (
    [taxonomy] => language
    [terms] => Array
    (
    [0] => en
    )

    [field] => slug
    [operator] => IN
    [include_children] => 1
    )

    [1] => Array
    (
    [taxonomy] => product_cat
    [terms] => Array
    (
    [0] => my-group-products
    )

    [field] => slug
    [operator] => IN
    [include_children] => 1
    )

    )

    • This topic was modified 4 years, 4 months ago by Hrohh.
Viewing 4 replies - 1 through 4 (of 4 total)
  • Thread Starter Hrohh

    (@hrohh)

    My new function

    	protected function get_current_term( $q = null) {
    		global $wp_query;
    
    		$term_slug = '';
    
    		$q = !is_null( $q ) ? $q : $wp_query;
    
    	    $queries = !empty($q->tax_query) ? $q->tax_query->queries : '';
    
            if ( !empty( $queries ) && !empty($queries[0]['taxonomy']) ) {
                $lang = array_search( 'language', array_column( $queries , 'taxonomy' ) );
                if ( $lang )
                    array_splice( $queries, $lang, 1 );
            }
    
    	    if ( !empty($queries) && !empty($queries[0]['taxonomy'])) {
    	    	$taxonomy = $queries[0]['taxonomy'];
    
    	    	$taxonomy_object = get_taxonomy( $taxonomy );
    
    	    	// Only if term have ui. Example language taxonomy Polylang.
    	    	if ($taxonomy_object && $taxonomy_object->show_ui ) {
    			    // Need term slug, not term id
    			    if ('term_id' == $queries[0]['field'] ) {
    				    $term_id = $queries[0]['terms'][0];
    				    $term = get_term($term_id, $taxonomy);
    				    $term_slug = $term->slug;
    			    } else {
    				    $term_slug = $queries[0]['terms'][0];
    			    }
    		    }
    	    }
    
    	    return $term_slug;
        }
    
    Thread Starter Hrohh

    (@hrohh)

    Please add some filter for excluding taxonomy. I dont want ordering products based on languages in Woocommerce product category page. Thank you

    Plugin Author briarinc

    (@briarinc)

    Thread Starter Hrohh

    (@hrohh)

    Hi, thank you so much, it works ok now ! ??
    Only some PHP notice in different instance of WordPress I have :O)

    [05-Nov-2020 19:26:34 UTC] PHP Notice: Trying to get property ‘queries’ of non-object in /home/ttt/domains/ttt.com/public_html/wordpress/wp-content/plugins/anything-order-by-terms/modules/base/class.php on line 282
    [05-Nov-2020 19:26:34 UTC] PHP Warning: Invalid argument supplied for foreach() in /home/ttt/domains/ttt.com/public_html/wordpress/wp-content/plugins/anything-order-by-terms/modules/base/class.php on line 282

    • This reply was modified 4 years, 4 months ago by Hrohh.
Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Polylang issue’ is closed to new replies.