Make Selected Mutiselect Items “selected”

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 … Read more

post__in works but also prints the word Array

Array is how PHP represents an array when it is converted to a string: echo array( /* anything in here */ ); // output: Array Fortunately for you, PHP doesn’t really like converting arrays to strings, so it will give an error like this: PHP Notice: Array to string conversion in /somefile.php on line 345 … Read more

Comma seperated list of ID’s as an array?

WP has a lot of nifty functions in the corners for such stuff. Try this: if ( !empty( $categories ) ) { $excluded_categories = wp_list_pluck( $categories, ‘term_id’); $excluded_categories = implode(‘,’, $excluded_categories); }

Updating wp_options with an array on save_post results in duplicated entries

I had something similar going on when I tried to use the wp_editor() function while inside a custom metabox. It was wanting to save multiple times. Take a look at this. // SAVE Metabox for admin response add_action(‘post_updated’, ‘display_jwl_wp_etickets_response_meta_box_save’); function display_jwl_wp_etickets_response_meta_box_save( $post_id ){ if( defined( ‘DOING_AUTOSAVE’ ) && DOING_AUTOSAVE ) return; if( !isset( $_POST[‘jwl_wp_etickets_editor_box_nonce_check’] ) … Read more

WordPress: How to use post_class() in an echo

The post_class() function just is a wrapper for get_post_class(). Keep in mind that the latter does not echo, but returns an Array so you have to do something like what post_class() does: $classes = join( ‘ ‘, get_post_class() ); Your code (could) would look like the following. I changed the if check as well to … Read more

Why does get_users suddenly return duplicates?

Seems like a silly question, but are there exactly 2 users in the database? Or are there more. The only thing I can see happening is because you are setting to 3, it’s looping back through. Another thing to try is checking the peterpanpan user, to see if he has the custom_role twice in his … Read more

Nice way to print_r arrays

I created a Kint plugin that works really well. I also integrates with the Debug Bar plugin. You can download it at: http://wordpress.org/extend/plugins/kint-debugger/ There are a few functions to help you out with WordPress specific globals: dump_wp_query() dump_wp() dump_post() For printing arrays in a styled, collapsible format you would do the following. $foo_bar = array( … Read more

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