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


7

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


6

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


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


4

To change <option value='http://someurl'>item one</option> <option value='http://someurl'>item two</option> <option value='http://someurl'>item three</option> to <option value='http://someurl'>1. item one</option> <option value='http://someurl'>2. item two</option> <option ...


3

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


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

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


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

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

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


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

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

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

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

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

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


2

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.


2

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


2

From my understanding of the question and your comment: I want to display all tags that are from posts that have been assigned to the specific category You would first need to get all the posts that have that tag assigned, loop through said posts and save the unique tags to an array. Finally, loop through the array and display them in the select list. ...


2

You can try use: MySQL WorkBench or other MySQL Client program; SSH to the Server and connect from the command prompt; Use PHPMyAdmin (make sure to password protect and set the right configuration); If you are really in need of an extra level of security you may want to consider setting up a VPN between your computer and the server where MySQL is ...


1

The default widgets do not offer any hooks for that. You have to replace the default widget and add your field to the new class. The other option would be using JavaScript to insert the field, and a filter for 'update_option_widget_' . $widget->id_base to save the value. I think the separate class is the cleaner approach.


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

You're probably better off to use get_users which returns an array of <?php // get all users, regardless of roll. If you do need to restrict by // role you can use the `role` argument: get_users(array('role' => 'author')); $uses = get_users(array('orderby' => 'nicename')); foreach ($users as $user) { // do stuff with $user, will have all the ...


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


1

Use get_the_ID() instead of the_ID(). the_ID() will echo'ed the ID of posting: <option value="<? the_ID(); ?>" <?php selected(get_the_ID(), $instance['post_to_display']); ?>><?php the_title(); ?></option>



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