Set Default Option Value as Blank for Meta Box
Before the foreach loop: foreach($authors as $author) { Add this empty option element: echo ‘<option value=”0″></option>’; Hope it works! 🙂
Before the foreach loop: foreach($authors as $author) { Add this empty option element: echo ‘<option value=”0″></option>’; Hope it works! 🙂
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
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
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.
To remove grand-children: <?php $args = array( ‘show_option_none’ => ‘Make’, child_of => 5, hide_empty => ‘0’, exclude => ‘0’, hierarchical => 1, depth => 1 ); ?> <b>Make </b><?php wp_dropdown_categories($args); ?> You need to add the hierarchical and depth parameters.
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
For the second part of your question: in your args variable, you can set the selected argument to whatever is saved in your database. See the codex for more details here. I’m currently working on the same issue, I’ll update and clarify once I figure everything out out. EDIT : Okay! I DID IT. Here’s … Read more
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
You can try using Chosen. I use it because it’s bundled with WooCommerce. It basically adds search box to the <select> element. I leave the styling to you. The easiest solution is to add it as a plugin. But you can add it to your theme if you want. Add the CSS and JS files: … Read more
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