How to populate a dropdown menu with option selected?

Use the selected HTML attribute. See w3schools docs. In your foreach loop, check if the current category matches the current iteration, and add the selected attribute to that option element. You are already getting the ID of each term, so you’ll need to also get the current category ID so you can check against it. … Read more

Custom Taxonomy Select Menu: Setting default option value?

Simply add an extra line before your for loop. For example: function get_color_dropdown($taxonomies, $args){ $myterms = get_terms($taxonomies, $args); $output =”<select onChange=”window.location.href=this.value”>”; $output .= “<option value=”default”>Shop by Color –></option>”; foreach($myterms as $term){ $root_url = get_bloginfo(‘url’); $term_taxonomy=$term->taxonomy; $term_slug=$term->slug; $term_name =$term->name; $link = $root_url.”https://wordpress.stackexchange.com/”.$term_taxonomy.”https://wordpress.stackexchange.com/”.$term_slug; $output .=”<option value=””.$link.””>”.$term_name.”</option>”; } $output .=”</select>”; return $output; } $taxonomies = array(‘pa_color’); $args = … Read more

Nav menu classes ‘has-dropdown’ but no ‘active’

Can you add the complete output code for the navigation menu. The code you pasted seems to be a stripped version. Moreover, WordPress adds ‘current_page_item’ class to the list item if it is currently being viewed. For more info, check this WordPress documentation on classes added to Navigation menu items.

Adding archive years to my menu

Hi Please follow below code do add dynamically year wise post under sub menu you want, I have added below code in functions.php add_filter( ‘wp_nav_menu_objects’, ‘ravs_add_menu_parent_class’ ); function ravs_add_menu_parent_class( $items ) { foreach ( $items as $item ) { //print_r($item);//print each menu item an get your parent menu item-id // get your menu item ID … Read more

Filter By Category Dropdown List With Custom Taxonomies

Just from skimming your code, it actually pretty much does the same as the WordPress API function wp_dropdown_categories(). It isn’t as sophisticated though, no insult intended. Because wp_dropdown_categories() is capable of displaying deeper leveled hierarchies – correctly – then your own function, I can’t see a reason for not just using wp_dropdown_categories() for your purpose. … Read more

Redirect wp_dropdown_pages() to an AJax request?

The following is the solution I came up with: <div id=”selection1″> <div id=”dropdown1″> <form id=”choice1″ action=”<?php bloginfo(‘url’); ?>” method=”get”> <?php $select = wp_dropdown_pages( array( ‘post_type’ => ‘page’, ‘show_option_none’ => ‘Select Car’, ‘echo’ => 0 ) ); echo $select; ?> </form> </div> <div id=”firstchoice”></div> </div> <script> $(‘#choice1’).change(function(){ //if the select value gets changed var png = … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)