Tag Info

Hot answers tagged

37

The parameter 'items_wrap' for wp_nav_menu() defaults to: '<ul id="%1$s" class="%2$s">%3$s</ul>' This a a template that is parsed with sprintf(): $nav_menu .= sprintf( $args->items_wrap , esc_attr( $wrap_id ) // %1$s , esc_attr( $wrap_class ) // %2$s , $items // %3$s ); The numbered placeholders – %1$s, ...


20

You can't do this with wp_nav_menu, because it outputs list items, and you'll generate invalid markup with your code. Try using wp_get_nav_menu_items() instead. A quick solution for a drop down menu with a custom walker: class Walker_Nav_Menu_Dropdown extends Walker_Nav_Menu{ // don't output children opening tag (`<ul>`) public function ...


9

Here is an example. I have also created a Gist with more generic code. add_action('add_meta_boxes', 'my_custom_metabox'); function my_custom_metabox() { add_meta_box('custom-taxonomy-dropdown','Brands','taxonomy_dropdowns_box','post','side','high'); } function taxonomy_dropdowns_box( $post ) { wp_nonce_field('custom-dropdown', 'dropdown-nonce'); ...


9

Actually, with a little digging this is quite easy to do. WooCommerce has already set up a filter so all you have to do it add a small snippet in your functions.php file. // Modify the default WooCommerce orderby dropdown // // Options: menu_order, popularity, rating, date, price, price-desc function my_woocommerce_catalog_orderby( $orderby ) { ...


6

You'll need to use get_posts and roll your own drop down. Something like this (somewhere in functions.php): <?php function wpse34320_type_dropdown( $post_type ) { $posts = get_posts( array( 'post_type' => $post_type, 'numberposts' => -1 ) ); if( ! $posts ) return; $out = '<select ...


6

I downloaded this plugin and took a look and it does work as advertised for me. The function it uses for displaying the page list is: wp_list_pages(array( 'sort_column'=>'menu_order', 'depth'=>'4', 'title_li'=>'', 'exclude'=>$exclude )); ?> Which is very straightforward and does very explicitly order ...


4

Sorry about that feels a bit weird answering ones own question, but here you go.... Firstly declare the variable: (customcategory) global $userdata; $errors = array(); $title = trim($_POST['wpuf_post_title']); $customcategory = trim($_POST['customcategory']); $content = trim($_POST['wpuf_post_content']); $tags = ...


4

This suppose you have a custom post type "sponsors" and a custom taxonomy "types"... function custom_meta_box() { remove_meta_box( 'tagsdiv-types', 'sponsors', 'side' ); add_meta_box( 'tagsdiv-types', 'Types', 'types_meta_box', 'sponsors', 'side' ); } add_action('add_meta_boxes', 'custom_meta_box'); /* Prints the taxonomy box content */ function ...


4

This is what I do: Static Options <select id="<?php echo $this->get_field_id('posttype'); ?>" name="<?php echo $this->get_field_name('posttype'); ?>" class="widefat" style="width:100%;"> <option <?php selected( $instance['posttype'], 'Option 1'); ?> value="Option 1">Option 1</option> <option <?php ...


3

Here is a quick snippet I use to get started on my projects: The first step is to add some code to the functions.php file. This is what will enable the WordPress Custom Navigation. The controls will be in Appearance>Menu's once your finished. Code for functions.php: <?php add_action( 'init', 'register_my_menus' ); function register_my_menus() { ...


3

You can use the standard WordPress function, get the dropdown already formatted and solve both problems at once. Like so: define( 'WP_USE_THEMES', false ); require( './wp-load.php' ); wp_dropdown_categories( array( 'child_of' => 0, 'class' => 'postform', 'depth' => 0, 'echo' => 1, 'exclude' => ...


3

Yes, we can sort Wordpress posts in different orders, You can do following sorts without installing plugins. sort post by date ( ascending / descending ) Sort post by title (ascending / descending ) Sort post by comment count ( ascending / descending ) -- These are just basic we can do even more using categories and tags etc Wordpress already stores the ...


3

There are couple of things wrong with your code... when filtering it is not term that gives the ID of the term, but business (in this case), since this is the name you've provided for the drop-down menu. Replace all instances of term with business Taxonomy is not set when filtering. Remove this check from parse_query function. The following worked for ...


3

A filter called wp_dropdown_pages exists in the wp_dropdown_pages() function. That filter allows you to modify the output of the function. However, for the thing you want to do I would not recommend using this filter since this will apply to all code that calls wp_dropdown_pages(), including plugins. So, one way to approach your situation may be to simply ...


3

It's called a 'Mega Menu', it allows a full HTML control over dropdown elements of a menu. There is a free option here - http://wordpress.org/extend/plugins/jquery-mega-menu/ - and CodeCanyon offers a lot premium and fancy mega menu plugins to be purchased.


3

You will need to write a custom walker extending Walker_Nav_Menu, more or less like so: class My_Custom_Nav_Walker extends Walker_Nav_Menu { function start_lvl(&$output, $depth = 0, $args = array()) { $output .= "\n<ul class=\"dropdown-menu\">\n"; } function start_el(&$output, $item, $depth = 0, $args = array(), $id = 0) { ...


3

Ok I found a solution thanks to this: Using wp_dropdown_categories in widget options Here is the code I used instead: function form( $instance ) { /* Default Widget Settings */ $defaults = array( 'title' => 'Highlight Category' ); $instance = wp_parse_args( (array) $instance, $defaults ); ?> <!-- Widget Title --> ...


3

I'm surprised it's all that slow but you can remove all but one of the database calls & most of the looping by passing the term data instead of just slugs to my_dropdown_categories() so get_terms() doesn't have to be called, plus a few other improvements (see comments) eg: function my_dropdown_categories( $taxonomy, $current_selected = '', $terms = ...


2

Try this /* Save selected data */ add_action( 'personal_options_update', 'save_user_fields' ); add_action( 'edit_user_profile_update', 'save_user_fields' ); function save_user_fields( $user_id ) { if ( !current_user_can( 'edit_user', $user_id ) ) return false; update_usermeta( $user_id, 'country', $_POST['country'] ); } add_action( ...


2

We can get the categories via get_categories() function (which will get the same categories as wp_dropdown_categories() function), but as array and without the markup. As the value is returned as array, we can loop through the categories and generate the HTML ourself. Usually, we would aim for a structure like this: <select name="categories"> ...


2

You can use wp_dropdown_categories() to create your dropdown: wp_dropdown_categories(array('taxonomy'=> 'post_tag','hide_empty' => 0, 'name' => 'my_tags')); Update the reason you are getting the term ID is because wp_dropdown_categories sets the ID's as values so instead of just echo'ing it out you need to get the term, something like: $term = ...


2

Take a look at the WooCommerce docs here: Tutorial – Customising checkout fields using actions and filters your code would look something like this: function my_custom_checkout_field( $checkout ) { woocommerce_form_field( 'my_field_name', array( 'type' => 'select', 'class' => array('my-field-class form-row-wide'), ...


2

The dot . in your code is evaluated as string litral, and not concatenation. Meaning if $inpCnt was equal to 5 for example, php will search for name='scrape['.5.'][sponsors]' id= and will fail to find it. You can either remove the dots while still using the double quotes: $sponsors = str_replace( "name='scrape['$inpCnt'][sponsors]' id=", ...


2

You can add new taxonomy with your own metabox since wp 3.8 by meta_box_cb "drop_cat()" - consist of rebuild original core category metabox wp-admin/includes/meta-boxes.php function realty_type() { $args = array( 'show_ui' => true, 'meta_box_cb' => 'drop_cat', ); register_taxonomy( 'realty_type', array( ...


2

You're initially submitting a POST request via a form with the sort parameters. When you click links to additional pages, you're just sending a GET request for the next page without those original POST vars, so they don't carry over to the additional pages and aren't picked up by your if(isset($_REQUEST['sort'])). Probably the simpler way to handle it is to ...


2

Update your form to include the term-id, instead of just <input type="checkbox" /> use <input type="checkbox" name="taxonomy_id[]" value="'. $industryterm->term_id .'" />. That way you are actually sending along some values, in this case the term id. And in the args for wp_insert_post() make sure to include something like this: 'tax_input' ...


2

I think the best way to do this is using the loop, in the loop you need to get the terms for all associated posts. <?php if (have_posts()) : <while (have_posts()) : the_post(); //thecode endwhile; endif; ?>


2

Ok, I was able to get the drop down working. I was not able figure out my second question though- How to populate the drop down with the terms/child terms of the current category being viewed? Here's how I got the drop down to work - The drop down -- <?php $terms = get_terms("videoscategory"); $count = count($terms); if ( $count > 0 ){ ...


2

Edited according to first comments and Pastebin code: <?php /* You can also leave 'action' blank: action="" */ ?> <form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>"> <select name="my_size" id="size" class="postform" onchange="submit();"> <option selected="selected">Choose a size</option> ...


2

WordPress has Custom Navigation Menus built-in. Simply register a theme_location for each menu in functions.php, then go to Dashboard -> Appearance -> Menus to create the custom menu(s), and apply the custom menu(s) to the appropriate Theme Location(s). The rest is a matter of CSS (or jQuery, if you really want to go that route).



Only top voted, non community-wiki answers of a minimum length are eligible