Viewing 6 replies - 1 through 6 (of 6 total)
  • Thread Starter teste123456

    (@teste123456)

    I’ve found this plugin, but this does on the admin side only.

    https://www.ads-software.com/plugins/acategory-dropdown-list/screenshots/

    Thread Starter teste123456

    (@teste123456)

    Hi,

    It is not listing posts because you are not including the category parameter in query argument array. To list posts of selected category, please add the selected drop down category name to query argument array.

    $query = new WP_Query( array( 'category_name' => $_GET['dropdown_name'] ) );

    Please replace ‘dropdown_name’ with the category dropdown name attribute value.

    Thread Starter teste123456

    (@teste123456)

    Thankyou presstiger, but where do i put this code?
    $query = new WP_Query( array( 'category_name' => $_GET['dropdown_name'] ) );

    add_shortcode('WP_Taxonomy_Chained_Select','WP_Taxonomy_Chained_Select_Function');
    function WP_Taxonomy_Chained_Select_Function($atts) {
    	$output = '';
    	// SET ALL THE ARGUMENTS THAT MATTER,
    	// USING THE $atts ARRAY IF PRESENT,
    	// OR DEFAULTS SET BELOW
    
    	// set custom taxonomy name or use Categories
    	$taxonomy = $atts['taxonomy'] ? : 'category';
    	// set CSS id of select element, use taxonomy name if empty
    	$id = $atts['id']?:$taxonomy;
    	// set CSS class of select element, use taxonomy name if empty
    	$class = $atts['class']?:$taxonomy;
    	// set input name, use taxonomy name if empty
    	$name = $atts['name']?:$taxonomy.'[]';
    	// set sort orderby, use name if empty
    	$orderby = $atts['orderby']?:'name';
    	// set sort order, use ASC if empty
    	$order = $atts['order']?:'ASC';
    	// set hide_empty, use false if empty
    	$hide_empty = $atts['hide_empty']?:false;
    	// show_option_none text or use taxonomy name stripped of dashes and underscores, each word capitalized
    	$show_option_none = $atts['show_option_none']?: 'Select '.ucwords(str_replace(array('-','_'),' ',$taxonomy));
    	// allow selected element to be specified, else use show_option_none
    	$sel = $atts['selected']?:'';
    	$show_option_none_sub = $atts['show_option_none_sub']?:false;
    
    $output .= '<div id="my_'. $id .'">';
    
    	$args = array(
    	    'show_option_none' 	=> $show_option_none,
    	    'orderby'            => $orderby,
    	    'order'              => $order,
    	    'name'               => $name,
    	    'hierarchical'       => 0, // hierarchical is presumed
    	    'parent'			=> 0, // always top level of hierarchy
    	    'echo'			=> 0, // no, we want to play with it as a variable first
    	    'class'              => $class,
    	    'id'              	=> $id,
    	    'selected'			=> $sel,
    	    'taxonomy'			=> $taxonomy,
    	    'hide_empty'		=> $hide_empty
    	);
    	$dropdown = wp_dropdown_categories( $args );
    	$strSearch = '<select ';
    	$strReplace ='<select onchange="jQuery(\'.select_sub.'.$id.'\').hide(); jQuery(\'#sub\'+this.options[this.selectedIndex].value).toggle(); jQuery(\'select.'.$taxonomy.'_func\').prop(\'selectedIndex\', 0);"';
    	$dropdown = str_replace($strSearch,$strReplace,$dropdown);
    	$output .= $dropdown;
    	$parent = get_terms( $taxonomy, array ('parent'=> 0,'hide_empty'=> false, 'orderby'=>$orderby, 'order'=> $order) );
    	foreach ($parent as $term ) {
    		if(count(get_terms( $taxonomy, array ('parent'=> $term->term_id,'hide_empty'=> false, 'orderby'=>$orderby, 'order'=> $order) )) > 0) {
    			$output .= '
    			<div class="select_sub '. $id .'" id="sub'. $term->term_id .'" style="display:none;">';
    			$dropdown = wp_dropdown_categories( array('taxonomy'=> $taxonomy,'show_option_none' 	=> $show_option_none_sub?:'Select '.$term->name.' Focus','name'=> $name,'parent'=> $term->term_id,'id'=>'sel'.$term->term_id,'hide_empty'=> false,'echo'=>0,'orderby'=>$orderby,'order'=>$order) );
    			$dropdown = str_replace("class='postform' >","class='".$taxonomy."_func'>",$dropdown);
    			$output .= $dropdown."	</div>";
    		}
    
    	}
    	$output .= "</div>
    	<script>
    	function ".$taxonomy."() {
    	  jQuery('#my_".$id." select option:selected').each(function () {
    		 jQuery('#".$id." select').prop('selectedIndex', 0);
    		 jQuery('.select_sub').hide();
    		 });
    	}
    	</script>";
    
    	return $output;
    }
    Thread Starter teste123456

    (@teste123456)

    which line do i insert your code?

    Thread Starter teste123456

    (@teste123456)

    I’ve found two ready solutions:

    1-
    https://www.ads-software.com/plugins/ultimate-wp-query-search-filter/screenshots/
    https://www.ads-software.com/support/topic/subcategories-on-dropdown?replies=9

    2 –
    https://codecanyon.net/item/wordpress-meta-data-taxonomies-filter/7002700

    But at the end of the day i was really looking to make my own code anyway.
    Hope that this helps someone.

    Any help for a custom made solution like @presstigers mentioned?

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘2 Dropdowns for category and subcategory’ is closed to new replies.