Problem with wp_update_post

The first argument of array_merge is the array of old values pulled from the original post, not your new values, so I’d guess you’re passing an invalid post ID. In your array of new values, I think you want to set post ID to $page_check_404->ID, not $ss_404_post_id.

How to check an array of $curauth fields?

Try <?php if ( !empty( array ( $curauth->facebook ) ) || !empty ( array ( $curauth->linkedin ) ) || !empty( array( $curauth->twitter ) ) ) { echo ‘echo me if any $curauth info exists’; } ?> Note: This can be all on fewer lines, I’ve just put in additional line-breaks to make it all fit … Read more

How to validate register settings array

Personally I’d do it the same way, since it seems to be the only point where you can examine user input and validate it. Also, heavily borrowing from code sample in this excellent article: function wpPartValidate_settings( $input ) { if ( check_admin_referer( ‘wpPart_nonce_field’, ‘wpPart_nonce_verify_adm’ ) ) { // Create our array for storing the validated … Read more

How to add day number and initial to my post graph?

I would go like this: A. Use the Unix timestamp as array key. $comment_counts[$date->format(‘U’)] = $query->post_count; B. Loop with key included. foreach( $comment_counts as $count_key => $count ) : Then you obtain the day number and the initial of the day from the key: // “d” means with leading zero, use “j” in place of … Read more

Sort a custom post type array numerically

get_terms function will return an array of object. Each of them has term_id field which contains id of a term. Just use it instead of slug and you will have what you need: <?php $terms = get_terms(“ratios”); if ( $count($terms) > 0 ){ foreach ( $terms as $term ) { echo “<option value=”” . $term->term_id … Read more

Get posts id in array by meta value and key

Use the meta_key, meta_value, and fields parameters. Example using get_posts(): (Take note though, get_posts() ignores or doesn’t include sticky posts.) $meta_key = ‘hide_rss’; $meta_value=”yes”; $post_ids = get_posts( [ ‘meta_key’ => $meta_key, ‘meta_value’ => $meta_value, ‘fields’ => ‘ids’, ] ); Or using new WP_Query(): $meta_key = ‘hide_rss’; $meta_value=”yes”; $q = new WP_Query(); $post_ids = $q->query( [ … 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

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

settings api store multiple array

I put this in the form so it knows its editting: <form method=”post” action=”options.php”> <?php settings_fields(‘venues_section’); ?> <input type=”hidden” name=”editmode” value=”<?php echo $editmode; ?>” /> <input type=”hidden” name=”venue_id” value=”<?php echo $venue_id; ?>” /> <?php submit_button(); ?> </form> The receiving validation function can then handle that by doing something like this: function venues_validation_callback($input){ $venues = get_option(‘venues’); … Read more