array_map() for sanitizing $_POST

It’s probably not a great idea. Firstly, if you’ve got other field types then you should probably use more appropriate functions. For example, textarea fields should be sanitised with sanitize_textarea_field(), and color pickers should be sanitized with sanitize_hex_color(). You should also consider that $_POST likely also contains fields that you don’t want to save, such … Read more

How do I update a specific object in an array, in user meta?

You can just assign a new value to the 1h_userbadge_comments25 key. Like so… <?php $meta_value = get_user_meta($user_id, ‘lh_userbadges’, false); // just assign this key a new value $meta_value[‘lh_userbadge_comments25’] = 25; Then just save it again. <?php update_user_meta( $user_id, ‘lh_userbadges’, $meta_value ); Whether or not storing all of those values as an array is the correct … Read more

Saving an array in a single custom field

You can json_encode() it which will make it a string that you can put into a custom field then just ensure you json_decode() it to bring it back to an object or json_decode($data, true) to bring it back as an array $arr = array(“Accounting”=>”Peter”, “Finance”=>”Ben”, “Marketing”=>”Joe”); update_post_meta($post_id, “my_custom_meta_key”, json_encode($arr)); $json_data = get_post_meta($post_id, “my_custom_meta_key”, true); // … Read more

Need to get specific data from array

You should be able to rewrite what you have about and also use get_permalink as @Benoti stated while omitting the $split array. get_permalink accepts either the Post ID or a post object. global $rental; $images = get_children( array( ‘post_parent’ => $rental_id, ‘post_status’ => ‘inherit’, ‘post_type’ => ‘attachment’, ‘post_mime_type’ => ‘image’, ‘order’ => ‘ASC’, ‘orderby’ => … Read more

Looping through WP_Post Object

Based on what you said about a post being completed, you can check if its status is completed and if it is, then point to the title: foreach ( $lessons as $lesson ){ if( $lesson[‘status’] == ‘completed’ ){ echo $lesson[‘post’]->post_title; } }

How to save WordPress Options as an array?

Have you tried… <input type=”text” name=”my_options[option1]” value=”<?php echo $options[‘option1’]; ?>” /> <input type=”text” name=”my_options[option2]” value=”<?php echo $options[‘option2’]; ?>” /> <input type=”text” name=”my_options[option3]” value=”<?php echo $options[‘option3′]; ?>” />? I should say though (and maybe you have), that you should register your settings and perform necessary validation checks on the input – or if you really don’t … Read more

Get Term names from WP Term Object

Here’s an alternative using the handy wp_list_pluck(): $terms = get_terms(array( ‘taxonomy’ => ‘category’, ‘hide_empty’ => false, )); $slugs = wp_list_pluck( $terms, ‘slug’ ); $names = wp_list_pluck( $terms, ‘name’ ); where we pluck out the wanted field into an array.

if is_singular array not working as expected

You are using an incorrect check here. is_singular() returns true when a post is from the specified post type or post types or the default post types when none is specified. You cannot target specific single posts with is_singular() You have to use is_single to target a specific post if ( is_single( ‘post-a’ ) { … Read more

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