• Resolved ikanaspencer

    (@ikanaspencer)


    For job submission I want to have the “job categories” form return these items as a dynamic 3-part drop down.

    This is how our taxonomy is structured and currently has over 800 records which is far too much for a user to sift through:

    -Top Level
    –Second Level
    —Thrid Level

    However if we can populate the fields dynamicly possibly via Ajax or Gravity forms or other the most anyone would ever have to select from is 34 or so records.

    What is the best suggestion here?

    Should I use Ajax and the standard hooks and filters to implement this?

    Can I use gravity forms to do this since one of our guys knows that best?

    Is this a feature that can be requested?

    https://www.ads-software.com/plugins/wp-job-manager/

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author Mike Jolley (a11n)

    (@mikejolley)

    This would need to be custom, and would probably need to use ajax yes (endpoint to return terms of X).

    So select top level, ajax call, append 2nd level to form.

    Thread Starter ikanaspencer

    (@ikanaspencer)

    I had an almost working solution that is basically this code:

    in the functions.php of the child theme:

    function implement_ajax() {
    if(isset($_POST['main_catid']))
    			{
    			$categories=  get_categories('child_of='.$_POST['main_catid'].'&hide_empty=0');
    			  foreach ($categories as $cat) {
    				$option .= '<option value="'.$cat->term_id.'">';
    				$option .= $cat->cat_name;
    				$option .= ' ('.$cat->category_count.')';
    				$option .= '</option>';
    			  }
    			  echo '<option value="-1" selected="selected">Sub Categories</option>'.$option;
    			die();
    			} // end if
    }
    add_action('wp_ajax_my_special_ajax_call', 'implement_ajax');
    add_action('wp_ajax_nopriv_my_special_ajax_call', 'implement_ajax');//for users that are not logged in.
    
    if ( function_exists('register_sidebar') ) {
    	register_sidebar(array(
    		'before_widget' => '<li id="%1$s" class="widget %2$s">',
    		'after_widget' => '</li>',
    		'before_title' => '<h2 class="widgettitle">',
    		'after_title' => '</h2>',
    	));
    }

    For the job-submit.php template I added the following

    <script type="text/javascript">
    $(function(){
    			$('#main_cat').change(function(){
    					var $mainCat=$('#main_cat').val();
    
    					// call ajax
    					 $("#sub_cat").empty();
    												$.ajax({
    														url:"<?php bloginfo('wpurl'); ?>/wp-admin/admin-ajax.php",
    														type:'POST',
    														data:'action=my_special_ajax_call&main_catid=' + $mainCat,
    
    												   success:function(results)
    													   {
    														//  alert(results);
    														$("#sub_cat").removeAttr("disabled");
    														  $("#sub_cat").append(results);
    														}
    												   });
    
    										  }
    										  );
    });
    										  </script>
    wp_dropdown_categories('show_count=0&selected=-1&hierarchical=1&depth=1&hide_empty=0&exclude=1&show_option_none=Main Categories&name=main_cat');
    ?>

    This got us a start but now we have made some changes that look like this.

    $category_args = array(
    		'orderby' => 'name',
    		'order' => 'ASC',
    		'hide_empty' => false,
    		'fields' =>	'id=>name',
    	);
    	$category_args1 = $category_args;
    	$category_args1['parent'] = 0;
    	$job_categories1 = get_terms('job_listing_category', $category_args1);
    
        $fields['job']['_job_cat1'] = array(
            'label'     => __( 'Cat1', 'wp-job-manager' ),
            'type'      => 'select',
            'options' 	=> $job_categories1,
            'required'    => true,
            'placeholder' => '',
            'priority'    => 3.1,
        );
    
    	$category_args2 = $category_args;
    	/*$category_args2['parent'] = 1;*/
    	$job_categories2 = get_terms('job_listing_category', $category_args2);
    
        $fields['job']['_job_cat2'] = array(
            'label'     => __( 'Cat2', 'wp-job-manager' ),
            'type'      => 'select',
            'options' 	=> $job_categories2,
            'required'    => true,
            'placeholder' => '',
            'priority'    => 3.2,
        );
    
    	$category_args3 = $category_args;
    	/*$category_args3['parent'] = 2;*/
    	$job_categories3 = get_terms('job_listing_category', $category_args3);
    
        $fields['job']['_job_cat3'] = array(
            'label'     => __( 'Cat3', 'wp-job-manager' ),
            'type'      => 'select',
            'options' 	=> $job_categories3,
            'required'    => true,
            'placeholder' => '',
            'priority'    => 3.3,
        );
    
        return $fields;
    }
    
    /*
    	wp_dropdown_categories('show_count=0&selected=-1&hierarchical=1&depth=1&hide_empty=0&exclude=1&show_option_none=Main Categories&name=main_cat&taxonomy=job_listing_category');
    */
    
    function implement_ajax() {
        if(isset($_POST['main_catid']))
        {
            $categories=  get_categories('child_of='.$_POST['main_catid'].'&hide_empty=0&taxonomy=job_listing_category');
                foreach ($categories as $cat) {
                $option .= '<option value="'.$cat->term_id.'">';
                $option .= $cat->cat_name;
                $option .= ' ('.$cat->category_count.')';
                $option .= '</option>';
            }
            echo '<option value="-1" selected="selected">Sub Categories</option>'.$option;
            die();
        } // end if
    }
    add_action('wp_ajax_my_special_ajax_call', 'implement_ajax');
    
    //add_action('wp_ajax_nopriv_my_special_ajax_call', 'implement_ajax');//for users that are not logged in.
    
    if ( function_exists('register_sidebar') ) {
        register_sidebar(array(
            'before_widget' => '<li id="%1$s" class="widget %2$s">',
            'after_widget' => '</li>',
            'before_title' => '<h2 class="widgettitle">',
            'after_title' => '</h2>',
        ));
    }
    
    // Add our own function to filter the fields
    add_filter( 'submit_resume_form_fields', 'custom_submit_resume_form_fields' );

    I am kind of lost by these changes but if you can guide me in a good direction I would appreciate it. Also if you just know of someone we can hire to do this right we are willing to go that rout. I posted in the wordpress job section but got so many low quality responses I have not been able to effectivly sort through them all.

    Plugin Contributor Adam Heckler

    (@adamkheckler)

    Thread Starter ikanaspencer

    (@ikanaspencer)

    Thank you for the resources I will check into them.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Dynamic possible ajax style menu’ is closed to new replies.