WP_insert_term how to insert multiple values as taxonomny term?

I would build the input fields for terms as array of inputs. Like this (note the [] inthe name attribute: <input name=”input_name[]” type=”text” value=””> <input name=”input_name[]” type=”text” value=””> <input name=”input_name[]” type=”text” value=””> Then, in PHP: //Now $_POST[‘input_name’]; is an array //get the array and sanitize it $input_terms = array_map( ‘sanitize_text_field’, $_POST[‘input_name’] ); //Set the array … Read more

Return array of categories to php function

this should do it: $categories = get_categories(); foreach( $categories as $category ) { echo ‘<input type=”checkbox” name=” . $category->slug . “” value=”‘ . $category->term_id . ‘” /> ‘ . $category->name . ‘<br />’ . “\n”; } and you can change/order the list by feeding arguments to get_categories(): http://codex.wordpress.org/Function_Reference/get_categories

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); }

How do I properly format the user_role array?

try : a:5:{ s:13:”administrator”;a:2:{s:4:”name”;s:13:”Administrator”;s:12:”capabilities”;a:54:{s:13:”switch_themes”;b:1;s:11:”edit_themes”;b:1;s:16:”activate_plugins”;b:1;s:12:”edit_plugins”;b:1;s:10:”edit_users”;b:1;s:10:”edit_files”;b:1;s:14:”manage_options”;b:1;s:17:”moderate_comments”;b:1;s:17:”manage_categories”;b:1;s:12:”manage_links”;b:1;s:12:”upload_files”;b:1;s:6:”import”;b:1;s:15:”unfiltered_html”;b:1;s:10:”edit_posts”;b:1;s:17:”edit_others_posts”;b:1;s:20:”edit_published_posts”;b:1;s:13:”publish_posts”;b:1;s:10:”edit_pages”;b:1;s:4:”read”;b:1;s:8:”level_10″;b:1;s:7:”level_9″;b:1;s:7:”level_8″;b:1;s:7:”level_7″;b:1;s:7:”level_6″;b:1;s:7:”level_5″;b:1;s:7:”level_4″;b:1;s:7:”level_3″;b:1;s:7:”level_2″;b:1;s:7:”level_1″;b:1;s:7:”level_0″;b:1;s:17:”edit_others_pages”;b:1;s:20:”edit_published_pages”;b:1;s:13:”publish_pages”;b:1;s:12:”delete_pages”;b:1;s:19:”delete_others_pages”;b:1;s:22:”delete_published_pages”;b:1;s:12:”delete_posts”;b:1;s:19:”delete_others_posts”;b:1;s:22:”delete_published_posts”;b:1;s:20:”delete_private_posts”;b:1;s:18:”edit_private_posts”;b:1;s:18:”read_private_posts”;b:1;s:20:”delete_private_pages”;b:1;s:18:”edit_private_pages”;b:1;s:18:”read_private_pages”;b:1;s:12:”delete_users”;b:1;s:12:”create_users”;b:1;s:17:”unfiltered_upload”;b:1;s:14:”edit_dashboard”;b:1;s:14:”update_plugins”;b:1;s:14:”delete_plugins”;b:1;s:15:”install_plugins”;b:1;s:13:”update_themes”;b:1;s:14:”install_themes”;b:1;}} s:6:”editor”;a:2:{s:4:”name”;s:6:”Editor”;s:12:”capabilities”;a:34:{s:17:”moderate_comments”;b:1;s:17:”manage_categories”;b:1;s:12:”manage_links”;b:1;s:12:”upload_files”;b:1;s:15:”unfiltered_html”;b:1;s:10:”edit_posts”;b:1;s:17:”edit_others_posts”;b:1;s:20:”edit_published_posts”;b:1;s:13:”publish_posts”;b:1;s:10:”edit_pages”;b:1;s:4:”read”;b:1;s:7:”level_7″;b:1;s:7:”level_6″;b:1;s:7:”level_5″;b:1;s:7:”level_4″;b:1;s:7:”level_3″;b:1;s:7:”level_2″;b:1;s:7:”level_1″;b:1;s:7:”level_0″;b:1;s:17:”edit_others_pages”;b:1;s:20:”edit_published_pages”;b:1;s:13:”publish_pages”;b:1;s:12:”delete_pages”;b:1;s:19:”delete_others_pages”;b:1;s:22:”delete_published_pages”;b:1;s:12:”delete_posts”;b:1;s:19:”delete_others_posts”;b:1;s:22:”delete_published_posts”;b:1;s:20:”delete_private_posts”;b:1;s:18:”edit_private_posts”;b:1;s:18:”read_private_posts”;b:1;s:20:”delete_private_pages”;b:1;s:18:”edit_private_pages”;b:1;s:18:”read_private_pages”;b:1;}} s:6:”author”;a:2:{s:4:”name”;s:6:”Author”;s:12:”capabilities”;a:10:{s:12:”upload_files”;b:1;s:10:”edit_posts”;b:1;s:20:”edit_published_posts”;b:1;s:13:”publish_posts”;b:1;s:4:”read”;b:1;s:7:”level_2″;b:1;s:7:”level_1″;b:1;s:7:”level_0″;b:1;s:12:”delete_posts”;b:1;s:22:”delete_published_posts”;b:1;}} s:11:”contributor”;a:2:{s:4:”name”;s:11:”Contributor”;s:12:”capabilities”;a:5:{s:10:”edit_posts”;b:1;s:4:”read”;b:1;s:7:”level_1″;b:1;s:7:”level_0″;b:1;s:12:”delete_posts”;b:1;}} s:10:”subscriber”;a:2:{s:4:”name”;s:10:”Subscriber”;s:12:”capabilities”;a:2:{s:4:”read”;b:1;s:7:”level_0″;b:1;}}} which are the roles and capabilities that are set by default.

How to fetch serialized data from wordpress options

No, this won’t work: <?php echo get_option(‘notice_data[Message]’); ?> Because get_option pulls whole option value by option_name, it doesn’t pull by pieces of the serialized array. What you are asking for is a key (option_name) called literally notice_data[Message]. Assuming you’ve saved the option as notice_data you aren’t going to get a match, and I am not … Read more

Use Transient API to cache queries for all posts in all categories?

You’re saving every query object for each category to the same transient. Because this happens fast and time frame is one day, you’re always getting the query object for the first category back. Make your transient name variable with the category, e.g. like this: $query_category_posts = get_transient(‘cached_posts_’ . $category ); Of course you then need … Read more

shortcode to create dynamic dropdown box form shortcode attributes

Based on your example at the bottom of your question, and your statement that you would like something like that for readability, I’d do something like this: function dropdown_option($atts) { $dropid = (isset($atts[‘dropid’])) ? $atts[‘dropid’] : ”; global $sco_array; if (!empty($atts[‘value’]) && !empty($atts[‘text’])) { $sco_array[$dropid][$atts[‘value’]] = $atts[‘text’]; } } add_shortcode(‘sco’,’dropdown_option’); function sc_dropdown($atts) { $id = … Read more

assign 2 $args to one wp_query

array_merge does not work the way you expect/need it to, but honestly I am not sure why you are making this so complicated. All you need is: $args = array( ‘s’ => ‘keyword1 keyword2’, ‘orders’ => ‘DESC’, ‘showposts’ => 60 ); // var_dump($args); // debug $query = new WP_Query($args); var_dump($query->request); // debug The built is … Read more

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