Skip to content
Read For Learn
Read For Learn
  • Database
    • Oracle
    • SQL
  • C
  • C++
  • Java
  • Java Script
  • jQuery
  • PHP
Read For Learn
  • Database
    • Oracle
    • SQL
  • C
  • C++
  • Java
  • Java Script
  • jQuery
  • PHP

How to add and subtract user meta values after post meta update

Basically, I have ditched the function, and now update meta data with a click on a hyperlink.

It fires this code, and does exactly what I wanted.

In case anyone interested:

$current_user = wp_get_current_user();
$current_user_id =  $current_user->ID;
$author_id = get_post_field( 'post_author', $post_id );

$user_coins = get_user_meta( $current_user_id, 'usercoins' , true );
$author_coins = get_user_meta( $author_id, 'usercoins' , true );
$post_coins = get_post_meta( $post_id, 'postcoins', true );

$user_coins_sum = $user_coins - 1;
$author_coins_sum = $author_coins + 1;
$post_coins_sum = $post_coins + 1;

         
                
                update_user_meta( $current_user_id, 'usercoins', $user_coins_sum); 
                update_user_meta( $author_id, 'usercoins', $author_coins_sum); 
                update_post_meta( $post_id, 'postcoins', $post_coins_sum ); 


    

Related Posts:

  1. the_post_thumbnail() based on the Post ID
  2. Calling a method from functions.php on a click of a button
  3. How can update custom meta for all posts
  4. How to Display Image Meta underneath EVERY image in EVERY post
  5. How do I display a user’s previous orders as a select box option on a product?
  6. How to check if a meta value has already been assigned to any user?
  7. function to assign user role based on a field from usermeta
  8. Creating user status mode in WordPress
  9. How to abort saving data in save_extra_profile_fields function WordPress?
  10. Update user profile information from functions.php
  11. Read array in php?
  12. Countdown to date function?
  13. If Array Values Match Another Array’s Values, Then
  14. Shortcode for Listing Users from Meta Value?
  15. Unable to Call More than One Meta Box Output
  16. Hide a div when a custom field is empty
  17. Uses for function: wp_update_user
  18. How to check post meta isset or not empty during publish/save post?
  19. Include User ID in iFrame URL
  20. WP custom posts: filter results to custom taxonomy tag that corresponds to user meta field
  21. Delete post meta by serialized meta value
  22. Display current user metadata on WordPress page
  23. How Can I Display the Last Modified Date for User Profiles on WordPress?
  24. Get user by meta data key and velue
  25. Where do I implement this display of User Meta Data, and how to put it in a table?
  26. Add another role to a user when they click a button?
  27. Store custom field’s multiple values in one user meta key
  28. Get field in readable word
  29. Adding user meta to post meta wp_insert_post() not working
  30. Private messaging – Getting and displaying the avatar/url of a message recipient
  31. Postmeta not saving
  32. Get author meta of all writers
  33. get_post_meta no longer working
  34. How to display the date under the post title?
  35. A better way to write this php function
  36. How do I get a function to work in single.php
  37. get_*_meta doesn’t always return an array
  38. Calling directories to load in wordpress
  39. WordPress add post format support not working
  40. Can I prevent the user from adding more than two levels deep of terms inside of a taxonomy metabox?
  41. Image media upload metabox
  42. How to remove the cufon script from Dzonia Lite theme [closed]
  43. How to remove or change the “W” icon in “My Sites”?
  44. get a simple array of all of the term names that exist in all taxonomies
  45. Login/logout in header
  46. How to display posts by current user in a drop down
  47. Logged in user ID as post ID
  48. How does WordPress insert Paragraphs in posts
  49. WordPress Access allowed to fewer pages till user logs in
  50. Linking text within textarea of custom meta box
  51. Show css depending on activity type in BuddyPress activity-loop [closed]
  52. only show container with next/prev links if they exist?
  53. How to combine wordpress_logged_in cookies in one cookie?
  54. Populate dropdown with Child Pages based on Parent Page chosen
  55. How can I remove a function that has been added to wordpress with add_filter?
  56. Change the WP Video Shortcode Output
  57. Show categories then when clicked on a category list all sub category and when clicked show all posts in that sub category
  58. remove wp floating submenu in wp dashboard
  59. How to put “Read more” link in Custom Excerpt inside p tag?
  60. Two Different Links for Same Product – WooCommerce [closed]
  61. ACF: how do I get the fields and its values of a specific group?
  62. How to store data from multiple forms using ajax and php
  63. How to control WordPress image metadata (using Imagick)?
  64. How to add seperate classes to no-search-result and found-search-result pages on wordrpess search – is_search()
  65. Get value from shortcode to do something
  66. PHP 8, AJAX mail form to function.php doesn’t work
  67. How do I add custom bulk actions to multiple custom post types?
  68. Error when adding excerpt to the content through functions.php
  69. Automatically adding new post categories to menu
  70. Add data attribute to each li in menu
  71. Get post id in a function when edit/add a post
  72. Making BuddyPress Activity Stream (Post Type) Featured Images Clickable [closed]
  73. How to complete two other input fields, completed the first
  74. Prev/Next child navigation for current page modifications?
  75. Adding rel tag to all external links
  76. Sort custom meta column by other meta value
  77. adding custom user input fields in WordPress admin dashboard gives error The link you followed has expired. Please try again
  78. How can I apply_filters from inside a function?
  79. what is the best practice to add new field to an api route
  80. Retrieve $_POST data submitted from external URL in WordPress(NOT API)
  81. Store multiple custom field as post meta per post(css, js, html, 2 link) [closed]
  82. How to upload a file to a folder named after the user_id via plugin
  83. Pass Category Name, Description and Photo into variables to pass to jQuery
  84. Use DOMDocument with ob_start breaks my HTML code
  85. Auto-update products after they were published – Woocommerce
  86. How to prevent WP_Query function from returning all posts when empty?
  87. How to VAR_DUMP a $variable during checkout process (Is my product meta callable?)
  88. wp_trim_words() does not work with my code Am I doing any mistake in my code?
  89. JS file work only in index page
  90. Display a specific category of products in shop page and disable code for specific actions
  91. Woocommerce related product text
  92. esc_html_e() is not translating string in wordpress [closed]
  93. Removing “wpautop” (auto tags) only on certain pages?
  94. Fatal error: Uncaught Error: Call to undefined function test()
  95. How to pick the default selected value in wordpress dropdown?
  96. get_post_meta not working on publishing
  97. Using WP-API and SSE not authenticating user ID
  98. Need help with Google drive API [closed]
  99. Woocommerce: hook action/filter I could use to add variation id and price with each attribute opt on WooCommerce Rest api
  100. Validate functions before inserting then into functions.php
Categories PHP Tags functions, php, post-meta, user-meta
WordPress Theme/Plugin Information API Response to Text and Button
Change a customizer control based on another control’s value dynamically

Recommended Hostings

Cloudways: Realize Your Website's Potential With Flexible & Affordable Hosting. 24/7/365 Support, Managed Security, Automated Backups, and 24/7 Real-time Monitoring.

FastComet: Fast SSD Hosting, Free Migration, Hack-Free Security, 24/7 Super Fast Support, 45 Day Money Back Guarantee.

Recent Added Topics

  • Bug in translation system: load_theme_textdomain() returns true, files are available and accessible but the language defaults to english
  • Custom Elementor controls not appearing in the widget Advanced tab using injection hooks
  • Get the name of the template/*html file used
  • Trying to Add Paging to Single Post Page
  • Sharing media files between live and staging servers
  • How to display the description of a custom post type in the dashboard?
  • Critical error on image display
  • Copying WP data and files into new install?
  • How to determine the DirectAdmin WordPress backup date?
  • How to get list of ALL tables in the database?
© 2026 Read For Learn
  • Database
    • Oracle
    • SQL
  • algorithm
  • asp.net
  • assembly
  • binary
  • c#
  • Git
  • hex
  • HTML
  • iOS
  • language angnostic
  • math
  • matlab
  • Tips & Trick
  • Tools
  • windows
  • C
  • C++
  • Java
  • javascript
  • Python
  • R
  • Java Script
  • jQuery
  • PHP
  • WordPress