Ich versuche, einen benutzerdefinierten Filter für WooCommerce zu erstellen
Ich habe 3 verschiedene Attribute, jeder von ihnen hat 10 Werte.
Ich ziehe diese Attribute mit 3 verschiedenen Schleifen wie folgt.
- <a href='https://wordpress.stackexchange.com/questions/287806/custom-products-filter/ term_id; ?>' data-tax="https://wordpress.stackexchange.com/questions/287806/custom-products-filter/ taxonomy; ?>" > https://wordpress.stackexchange.com/questions/287806/custom-products-filter/ name; ?>
-
- <a href='https://wordpress.stackexchange.com/questions/287806/custom-products-filter/ term_id; ?>' data-tax="https://wordpress.stackexchange.com/questions/287806/custom-products-filter/ taxonomy; ?>" > https://wordpress.stackexchange.com/questions/287806/custom-products-filter/ name; ?>
- <a href='https://wordpress.stackexchange.com/questions/287806/custom-products-filter/ term_id; ?>'> https://wordpress.stackexchange.com/questions/287806/custom-products-filter/ name; ?>
Hier ist AJAX
jQuery(document).ready(function($){ $('.filterz a').click(function(e){ e.preventDefault(); var attrid = $(this).attr('href'); var tax = $(this).attr('data-tax'); $.ajax({ type : 'POST', url: my_ajax_object.ajax_url, data: { action: 'get_filtered', attrid : attrid, tax : tax }, success: function(data){ $('.woocommerce ul.products').html(data); } }) }) })
und es gibt php ACTION
add_action('wp_ajax_get_filtered' , 'filtrator'); add_action('wp_ajax_nopriv_get_filtered' , 'filtrator'); function filtrator() { if( isset( $_POST['attrid'] ) ) { $attid = $_POST['attrid']; } if( isset( $_POST['tax'] ) ) { $tax = $_POST['tax']; } $_SESSION['taxs'] = array(); array_push($_SESSION['taxs'],$tax); $_SESSION['trmz'] = array(); array_push($_SESSION['trmz'],$attid); print_r($_SESSION); $afff = array( 'post_type' => 'product', 'tax_query' => array( 'relation' => 'OR', array( 'taxonomy' => array ($_SESSION['taxs']), 'field' => 'term_id', 'terms' => array( $_SESSION['trmz'][0] ) ), ) ); $fl = new WP_Query($afff); while( $fl -> have_posts() ) { $fl -> the_post(); ?> <?php } wp_die(); }
Ich habe versucht, eine Sitzung zu verwenden, um term_id’s zu einem Array zu setzen und dann Beiträge von diesen Daten zu erhalten. Und ich denke, ich gehe in die falsche Richtung, weil ich das gewünschte Ergebnis nicht bekommen kann.
Schätze jede Hilfe.