Tag Info

Hot answers tagged

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 ...


5

It looks like this is supported by Contact Form 7 natively, it's just not very obvious on how to make it happen. Here's a documentation page explaining the functionality: http://contactform7.com/selectable-recipient-with-pipes/ Basically all you have to do is put the values like so: Visible Value|actual-form-value What comes before the pipe "|" character ...


4

Yes, do an INNER JOIN, something like this should work: $values = $wpdb->get_col($wpdb->prepare(" SELECT meta_value FROM $wpdb->postmeta INNER JOIN $wpdb->posts {$wpdb->posts}.ID = {$wpdb->postmeta}.post_id WHERE meta_key= %s AND {$wpdb->posts}.post_status='publish'" ,$metakey )); I changed ...


3

You can use 'publish' === get_post_status( $id ), where $id could be the current page ID retrieved via get_the_ID() or any other.


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

you can do that using JQuery autocomplete plugin and once you have included all of the needed JS files just add this code after your new post form $terms = get_terms("post_tag"); $tags = ''; $count = count($terms); if ( $count > 0 ){ foreach ( $terms as $term ) { $tags .= '"'.$term->name.'", '; } $tags = substr($tags,0,-2); } ...


3

(I realize you're leaning away from this, but maybe if you can get it working, it's worthwhile. With the recent perfomance improvements in 3.4 for WP_Query, this could be worthwhile.) WP_Query is the right decision if this is a secondary loop. Otherwise, you might look into pre_get_posts. When you use WP_Query make sure that: You don't use a reserved ...


2

If I understand your question correctly, then it's a matter of joining the code from two answers from the following Questions of this Stack: Changing Top Level Items into Radio Buttons in the Categories Meta Box? Make parent categories not selectable This is the result, top-level categories are converted to radio buttons, so only one can be selected. ...


2

Look at the code for the tag box in wp-admin/includes/meta-boxes.php and the function tagBox in wp-admin/js/post.js. You may adapt or reuse these functions.


2

I'm assuming your $selected variable contains an array of values for the currently selected items? You can't use selected in this case (with multi select boxes) because it only compares two strings. It won't test to see if the value is in an array. Instead, use a ternary statement and in_array() <?php foreach ($cats as $cat_list ) { $selected = ...


2

Thanks to Ed Nailor & Kucrut ! http://ednailor.com/2011/01/24/adding-custom-css-classes-to-sidebar-widgets/ // __________________________________________________________ // // CUSTOM CLASS BY WIDGETS function kc_widget_form_extend( $instance, $widget ) { if ( !isset($instance['classes']) ) $instance['classes'] = null; /* Set your predetermied ...


2

You don't need to write these SQL queries. you can utilize WP_Query api. the following will display posts that has terms 'food-and-beverage' in tags. $query = new WP_Query( array( 'tag' => 'food-and-beverage' ) ); if you use different taxonomy, use that instead of tag. as you need to filter posts by using other options, you can check whole api ...


2

I believe this is what you were looking for. I moved back to using a class because what you were using would very easily conflict with someone else's code who decided to use the function names select_box_add_meta_box(), select_box_content() and/or select_box_save_postdata(), which is reasonably likely. The class name WPSE_85107 is only likely to conflict ...


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

You don't have to rebuild the metabox... you can just add a pseudo term via the get_terms filter. This will add an "All Terms" term to your checkbox list, (assuming a hierarchical taxonomy). add_filter( 'get_terms', 'wpa104168_all_terms', 10, 3 ); function wpa104168_all_terms ( $terms, $taxonomies, $args ){ if ( is_admin() && ...


2

If I have understood correctly, you could use get_the_ID() and compare the value with get_queried_object_id() to archive this: $args = array( 'post_type'=> 'portfolio', 'posts_per_page' =>100, 'offset'=> 0 ); $myposts = get_posts( $args ); $current_id = get_queried_object_id(); foreach ( $myposts as $post ) { setup_postdata( $post ); ...


2

(0. Retrieve the meta value with get_post_custom (in order to highlight the selected value in the select input).) Query posts with get_posts( array( 'post_type' => 'services', 'post_status' => 'publish' ) ) Loop through the results with foreach and build your select input. Hook into save_post (add_action('save_post', 'my_save_meta') to store the ...


2

If like me you'd like to have a default variation option selected without having to go through every Product and select a default via the admin then you need to alter the variable.php file which is located at woocommerce/templates/single-product/add-to-cart/variable.php (please do not alter the WooCommerce Plugin file - rather copy it to your Themes ...


1

I would suggest, that you switch from "URl query argument" style to arrays. This is a "feature" that is more a left over on some functions that is only available for backwards compatibility reasons than anything else. Here's a reworked version of your current arguments: wp_dropdown_pages( array( 'title_li' => '', 'depth' => TRUE, ...


1

The trouble is to do with how quick edit works - WordPress uses a hidden <div /> to generate the form, which will have already had select2 applied (and thusly, the positions already calculated). Your click event listener on the body won't fire when you need it, since the core event handler for quick edit returns false, stopping any event propagation. ...


1

Ahh it turns out it wasn't able to stay selected because I was using the "strtolower" function to remove capital letters. Which in turn caused there to be a mismatch between the selected value and the saved value in the database. add_action( 'show_user_profile', 'product_selection_field', 3 ); add_action( 'edit_user_profile', 'product_selection_field', 3 ...


1

I would remove the jQuery save function that was added... and then... Try this for the form function: public function form( $instance ) { // Code for editing/adding title and adding IDs to the <select> object // ... <?php printf ( '<select multiple="multiple" name="%s[]" id="%s" class="widefat" size="15" ...


1

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){ ...


1

You do not need to be messing with the database connection. WordPress provide a database object called $wpdb. It is not really clear what you are doing. Your title reads "help me select thumb", but your code is actually pulling a lot of different post statuses, not thumbnails. In fact, your code does not have anything to do with thumbnails at all, that I ...


1

You can use the following piece of code. <form action="<?php bloginfo('url'); ?>" method="get"> <?php $select = wp_dropdown_pages( array( 'post_type' => 'ce_artists', 'show_option_none' => 'Select Artist', 'echo' => 0 ...


1

The problem here is that you don’t allow PHP to read more than one value, because all values use the same name site_options[categorychoice], so they overwrite each other, and the last one wins. You need more brackets. Set the name attribute of your select element to site_options[categorychoice][], and all values will be read by PHP.


1

On the Product Edit page for the variable product, click on the "Variations" tab. Once you setup variations for the Colour you can set a "Default selection" at the bottom: http://cld.wthms.co/7LIv This will be the default option selected when a customer visits the page (if it is in stock). Example: http://cld.wthms.co/YQFO


1

The form reloads itself each time you save returning to the initial state where all are shown. What you can do is this: // Getting the value of the selected field var my_select_value = $('#widgets-right select.my-select').val(); // If there's no value selected, hide everything. if(my_select_value == 0){ $('.widget-test .row').hide(); } // Otherwise, ...


1

Ok, I've solved the issue myself. Turns out I had the name="_department" attribute duplicated in another field that was conflicting with my select field. My select saves just fine now I've edited that.


1

There're several things to note: get_settings() is deprecated and get_option() should be used instead WordPress comes with a function named select() that takes three arguments: Saved value, looped value, echo You're better off saving your key, than the HTML capable "title" element in your options. It's much safer to save in the DB an easier to compare as ...



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