最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

1+1 php counter inside the update_post_meta

matteradmin5PV0评论

how do you create a 1+1 php counter inside the update_post_meta?

this is the code i have so far:

$count = 1;
update_post_meta($bid_id, 'draftnumber', $count++);

but the counter is not moving, so i tried another one:

$counting = $counting + 1;
update_post_meta($bid_id, 'draftnumber', $counting);

but it's not working, am i not allowed to use $count++ inside the update_post_meta?

thankyou

how do you create a 1+1 php counter inside the update_post_meta?

this is the code i have so far:

$count = 1;
update_post_meta($bid_id, 'draftnumber', $count++);

but the counter is not moving, so i tried another one:

$counting = $counting + 1;
update_post_meta($bid_id, 'draftnumber', $counting);

but it's not working, am i not allowed to use $count++ inside the update_post_meta?

thankyou

Share Improve this question asked May 26, 2016 at 2:20 user94696user94696 2
  • Would you be able to post the rest of the function? Bit hard to tell whats going on with just this little snippet. – ngearing Commented May 26, 2016 at 2:26
  • $count++; right after $count = 1; so $count = 1; $count++; then update. It has to do with $bid_id I assume with this one. – Ismail Commented May 26, 2016 at 2:36
Add a comment  | 

1 Answer 1

Reset to default 6

If you're trying to update the number stored in the meta table, you need to load that value and increment it.

$count = get_post_meta( $bid_id, 'draftnumber', true );
if ( ! $count ) {
    $count = 0;  // if the meta value isn't set, use 0 as a default
                 // We'll be incrementing this right away so it'll be 1
}
$count++;
update_post_meta( $bid_id, 'draftnumber', $count );

References

  • get_post_meta()
  • update_post_meta()

Articles related to this article

Post a comment

comment list (0)

  1. No comments so far