Thursday, August 4, 2022
HomeWordPress Developmentfeatures - Get URLs for AJAX Filter Checkboxes WordPress

features – Get URLs for AJAX Filter Checkboxes WordPress


I’ve an issue with exhibiting and producing URLs for the pre-checked filter. So principally I want hyperlinks for a particular filter, for instance, I am selecting the Location, the Wage, the Kind of Work and click on search – it is producing a hyperlink with checked tags and I can ship this hyperlink to a different particular person.
Now I’ve a working filter but it surely’s not producing any hyperlink, and I am confused, may you please assist me? What ought to I do? It wasn’t me who created that code and undecided why they eliminated hyperlinks from there, and I can not discover how and the place 🙁
Right here is my code in perform.php

    add_action( 'wp_ajax_job-form', 'searchjob_form' );
add_action( 'wp_ajax_nopriv_job-form', 'searchjob_form' );
perform searchjob_form(){
    $filter = array('relation' => 'AND');
    $filtermeta = array('relation' => 'AND');
    $filterTitle="";
    
    // Set normal question
    $arg = array(
      'post_type' => 'product',
      'post_status' => 'publish'
    );
    
    if(isset($_REQUEST['sort_salary']) && $_REQUEST['sort_salary']=='min_salary'){
        $arg = array(
          'post_type' => 'product',
          'meta_key' => 'minimum_price',
          'orderby' => 'meta_value_num',
          'order' => 'ASC',
          'post_status' => 'publish'
        );
    }
    
    if(isset($_REQUEST['sort_salary']) && $_REQUEST['sort_salary']=='max_salary'){
        $arg = array(
          'post_type' => 'product',
          'meta_key' => 'maximum_price',
          'orderby' => 'meta_value_num',
          'order' => 'DESC',
          'post_status' => 'publish'
        );
    }
    
    // Filter for search question
    if(isset($_REQUEST['input_keyword']) && $_REQUEST['input_keyword']!=''){
        $arg['s'] = $_REQUEST['input_keyword'];
    }
    
    // Set meta question with argument
    if(isset($_REQUEST['location']) && $_REQUEST['location']!=''){
        $filter[] = array (
                'taxonomy' => 'location',
                'area' => 'slug',
                'phrases' => $_REQUEST['location']
            );
    }
    if(isset($_REQUEST['technology']) && $_REQUEST['technology']!=''){
        $filter[] = array (
                'taxonomy' => 'expertise',
                'area' => 'slug',
                'phrases' => $_REQUEST['technology']
            );
    }
    if(isset($_REQUEST['product_category']) && $_REQUEST['product_category']!=''){
        $filter[] = array (
                'taxonomy' => 'product_cat',
                'area' => 'slug',
                'phrases' => $_REQUEST['product_category']
            );
    }
    if(isset($_REQUEST['employment_type']) && $_REQUEST['employment_type']!=''){
        $filter[] = array (
                'taxonomy' => 'employment_type',
                'area' => 'slug',
                'phrases' => $_REQUEST['employment_type']
            );
    }
    if(isset($_REQUEST['seniority']) && $_REQUEST['seniority']!=''){
        $filter[] = array (
                'taxonomy' => 'seniority',
                'area' => 'slug',
                'phrases' => $_REQUEST['seniority']
            );
    }
    if(isset($_REQUEST['type_of_work']) && $_REQUEST['type_of_work']!=''){
        $filter[] = array (
                'taxonomy' => 'type_of_work',
                'area' => 'slug',
                'phrases' => $_REQUEST['type_of_work']
            );
    }
    if(isset($_REQUEST['language']) && $_REQUEST['language']!=''){
        $filter[] = array (
                'taxonomy' => 'language',
                'area' => 'slug',
                'phrases' => $_REQUEST['language']
            );
    }
    if(isset($_REQUEST['hot_offer']) && $_REQUEST['hot_offer']!=''){
        $filter[] = array (
                'taxonomy' => 'hot_offer',
                'area' => 'slug',
                'phrases' => $_REQUEST['hot_offer']
            );
    }
    if( !empty($filter) && depend($filter)>1 ){
        $arg['tax_query'] = $filter;   
    }
          
    if(isset($_REQUEST['max_price']) && $_REQUEST['max_price']!=''){
      
  
             $filtermeta[] = array(
                'key' => 'maximum_price',
                'worth' => array(trim($_REQUEST['max_price']), 1000000),
                'examine' => 'BETWEEN',
                'sort' => 'numeric'
            );      
    }

    if( !empty($filtermeta) && depend($filtermeta)>1 ){
        $arg['meta_query'] = $filtermeta;   
    }

and right here is the code for output on the template web page:

<div class="job-check-hotoffers-box lblcheck" id="job-check-hotoffers-box" type="show:none;">
                        <?php
                            $abilities = get_terms( array(
                                'taxonomy' => 'abilities',
                                'hide_empty' => false,
                            ) );
                            if($abilities) {
                            ?>
                        <?php foreach($abilities as $key => $ability){ ?>
                            <label><enter sort="checkbox" id="abilities<?php echo $key;?>" identify="abilities[]" class="abilities" worth="<?php echo ($skill->slug);?>"><?php echo ($skill->identify);?></label>
                        <?php } } ?>
                    </div>

and the JS for Search button

    $(doc).on('submit','type#frmSearch',perform(e){
  e.preventDefault();
  var request_method = $(this).attr('methodology');
  var form_data = $(this).serialize();
  $.ajax({
    url: ajaxurl,
    sort: 'POST',
    knowledge: form_data,
    beforeSend:perform(){
      $('#myjobList').html(ajaxloader);
      $('.job-check-location-box').cover();
      $('.job-check-technology-box').cover();
      $('.job-check-product-category-box').cover();
      $('.job-check-salary-box').cover();
      $('.job-check-employmenttype-box').cover();
      $('.job-check-seniority-box').cover();
      $('.job-check-typeofwork-box').cover();
      $('.job-check-language-box').cover();
      $('.job-check-hotoffers-box').cover();
    },
    success:perform(res){  
      if(res){
        $('#myjobList').html(res);
      }
    },
    error:perform (error) {
      //console.log(error);
    }
  });
});

Please, assist me 🙁 I noticed options for filter, however could not discover something associated to the checkboxes which may really work, since I am additionally utilizing GET as an alternative of POSTS
I’ve an issue with exhibiting and producing URLs for the pre-checked filter. So principally I want hyperlinks for a particular filter, for instance, I am selecting the Location, the Wage, the Kind of Work and click on search – it is producing a hyperlink with checked tags and I can ship this hyperlink to a different particular person.
Now I’ve a working filter but it surely’s not producing any hyperlink, and I am confused, may you please assist me? What ought to I do?
Right here is my code in perform.php

    add_action( 'wp_ajax_job-form', 'searchjob_form' );
add_action( 'wp_ajax_nopriv_job-form', 'searchjob_form' );
perform searchjob_form(){
    $filter = array('relation' => 'AND');
    $filtermeta = array('relation' => 'AND');
    $filterTitle="";
    
    // Set normal question
    $arg = array(
      'post_type' => 'product',
      'post_status' => 'publish'
    );
    
    if(isset($_REQUEST['sort_salary']) && $_REQUEST['sort_salary']=='min_salary'){
        $arg = array(
          'post_type' => 'product',
          'meta_key' => 'minimum_price',
          'orderby' => 'meta_value_num',
          'order' => 'ASC',
          'post_status' => 'publish'
        );
    }
    
    if(isset($_REQUEST['sort_salary']) && $_REQUEST['sort_salary']=='max_salary'){
        $arg = array(
          'post_type' => 'product',
          'meta_key' => 'maximum_price',
          'orderby' => 'meta_value_num',
          'order' => 'DESC',
          'post_status' => 'publish'
        );
    }
    
    // Filter for search question
    if(isset($_REQUEST['input_keyword']) && $_REQUEST['input_keyword']!=''){
        $arg['s'] = $_REQUEST['input_keyword'];
    }
    
    // Set meta question with argument
    if(isset($_REQUEST['location']) && $_REQUEST['location']!=''){
        $filter[] = array (
                'taxonomy' => 'location',
                'area' => 'slug',
                'phrases' => $_REQUEST['location']
            );
    }
    if(isset($_REQUEST['technology']) && $_REQUEST['technology']!=''){
        $filter[] = array (
                'taxonomy' => 'expertise',
                'area' => 'slug',
                'phrases' => $_REQUEST['technology']
            );
    }
    if(isset($_REQUEST['product_category']) && $_REQUEST['product_category']!=''){
        $filter[] = array (
                'taxonomy' => 'product_cat',
                'area' => 'slug',
                'phrases' => $_REQUEST['product_category']
            );
    }
    if(isset($_REQUEST['employment_type']) && $_REQUEST['employment_type']!=''){
        $filter[] = array (
                'taxonomy' => 'employment_type',
                'area' => 'slug',
                'phrases' => $_REQUEST['employment_type']
            );
    }
    if(isset($_REQUEST['seniority']) && $_REQUEST['seniority']!=''){
        $filter[] = array (
                'taxonomy' => 'seniority',
                'area' => 'slug',
                'phrases' => $_REQUEST['seniority']
            );
    }
    if(isset($_REQUEST['type_of_work']) && $_REQUEST['type_of_work']!=''){
        $filter[] = array (
                'taxonomy' => 'type_of_work',
                'area' => 'slug',
                'phrases' => $_REQUEST['type_of_work']
            );
    }
    if(isset($_REQUEST['language']) && $_REQUEST['language']!=''){
        $filter[] = array (
                'taxonomy' => 'language',
                'area' => 'slug',
                'phrases' => $_REQUEST['language']
            );
    }
    if(isset($_REQUEST['hot_offer']) && $_REQUEST['hot_offer']!=''){
        $filter[] = array (
                'taxonomy' => 'hot_offer',
                'area' => 'slug',
                'phrases' => $_REQUEST['hot_offer']
            );
    }
    if( !empty($filter) && depend($filter)>1 ){
        $arg['tax_query'] = $filter;   
    }
          
    if(isset($_REQUEST['max_price']) && $_REQUEST['max_price']!=''){
      
  
             $filtermeta[] = array(
                'key' => 'maximum_price',
                'worth' => array(trim($_REQUEST['max_price']), 1000000),
                'examine' => 'BETWEEN',
                'sort' => 'numeric'
            );      
    }

    if( !empty($filtermeta) && depend($filtermeta)>1 ){
        $arg['meta_query'] = $filtermeta;   
    }

and right here is the code for output on the template web page:

<div class="job-check-hotoffers-box lblcheck" id="job-check-hotoffers-box" type="show:none;">
                        <?php
                            $abilities = get_terms( array(
                                'taxonomy' => 'abilities',
                                'hide_empty' => false,
                            ) );
                            if($abilities) {
                            ?>
                        <?php foreach($abilities as $key => $ability){ ?>
                            <label><enter sort="checkbox" id="abilities<?php echo $key;?>" identify="abilities[]" class="abilities" worth="<?php echo ($skill->slug);?>"><?php echo ($skill->identify);?></label>
                        <?php } } ?>
                    </div>

and the JS for Search button

    $(doc).on('submit','type#frmSearch',perform(e){
  e.preventDefault();
  var request_method = $(this).attr('methodology');
  var form_data = $(this).serialize();
  $.ajax({
    url: ajaxurl,
    sort: 'POST',
    knowledge: form_data,
    beforeSend:perform(){
      $('#myjobList').html(ajaxloader);
      $('.job-check-location-box').cover();
      $('.job-check-technology-box').cover();
      $('.job-check-product-category-box').cover();
      $('.job-check-salary-box').cover();
      $('.job-check-employmenttype-box').cover();
      $('.job-check-seniority-box').cover();
      $('.job-check-typeofwork-box').cover();
      $('.job-check-language-box').cover();
      $('.job-check-hotoffers-box').cover();
    },
    success:perform(res){  
      if(res){
        $('#myjobList').html(res);
      }
    },
    error:perform (error) {
      //console.log(error);
    }
  });
});

Please, assist me 🙁 I noticed options for filter, however could not discover something associated to the checkboxes which may really work, since I am additionally utilizing GET as an alternative of POSTS

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments