Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

149
Views
¿Por qué mi valor de entrada no termina en términos de tax_query después de enviar el formulario con ajax?

Me gustaría cambiar mis términos tax_query después de enviar el formulario con ajax. El formulario Ajax se envía cada vez que hago clic en el elemento li. Por alguna razón, los datos no terminan en términos.

Configuración de formulario

 <?php $taxonomy = 'blog_categories'; $terms = get_terms($taxonomy); // Get all terms of a taxonomy if ($terms && !is_wp_error($terms)) : ?> <form action="<?php echo site_url() ?>/wp-admin/admin-ajax.php" method="POST" id="tax-filter"> <ul> <?php foreach ($terms as $term) { ?> <li class="blog-selection"><?= $term->name; ?></li> <input type="hidden" name="term" value="<?= $term->name; ?>"> <?php } ?> </ul> </form>

Ajax

 jQuery('li.blog-selection').each(function(){ jQuery(this).click(function() { var filter = jQuery(this); $.ajax({ url:filter.attr('action'), data:filter.serialize(), type:filter.attr('method'), success:function(data){ jQuery('.blog-wrapper__posts').html(data); } }); //debugging //console.log(filter.attr('method')); return false; }) });

WP_query

 $wp_query = new WP_Query(array( 'post_type' => 'blog', 'posts_per_page' => 6, 'paged' => $current_page_number, 'tax_query' => array( array( 'taxonomy' => 'blog_categories', 'terms' => $_POST['term'], 'field' => 'slug', ) ), ));
over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Tu código no accede al formulario de los filtros.

Te sugiero que hagas esto en su lugar

 $('#tax-filter').on("submit", function(e) { e.preventDefault() const $filter = $(this); $.ajax({ url: $filter.attr('action'), data: $filter.serialize(), type: $filter.attr('method'), success: function(data) { $('.blog-wrapper__posts').html(data); } }); }); $('li.blog-selection').on("click", function() { $('#tax-filter').submit() })
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!