• Hi guys,

    I was using this: Code here (Stackoverflow)

    I managed to customize the code to where I want it. It works 100% and the code is as shown below:

    <?php
    
    		function my_subcat_filter($post_type_id = 'company_listing', &$filter_get_value, $echo = TRUE) {
    
    		    $this_category = get_category(get_query_var('cat'),false);
    		    $mycat_ID = (int)get_query_var('cat');
    		    $myresults = get_categories('&child_of='.$mycat_ID.'&hide_empty');
    
    		    $myfield = array();
    			    foreach ($myresults as $myres) {
    			    	$myfield[] = $myres;
    			    }
    
    			// query current category id
    			$this_category = get_category(get_query_var('cat'),false);
    			$cat_ID = (int)get_query_var('cat');
    			//$filter_get_value = isset($_GET[$filter_id] : )
    			$myfilter = wp_dropdown_categories( array (
    					'show_option_all' => 'All',
    					'child_of' => $cat_ID,
    					'hide_empty' => 0
    					)
    				);
    my_subcat_filter('product', $product_filter);
    		$args = array('post_type' => 'company_listing', 'orderby' => $product_filter);
    		// The end
    	?>

    What I want to do now is to have the user category selection to filter using the Ajax or alternative. Loads the custom post based on what category is / was selected from the drop down menu.

    Let me know if you need anything extra.

  • The topic ‘Filtering by sub category [Advanced] using Ajax’ is closed to new replies.