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:
- the_post_thumbnail() based on the Post ID
- Calling a method from functions.php on a click of a button
- How can update custom meta for all posts
- How to Display Image Meta underneath EVERY image in EVERY post
- How do I display a user’s previous orders as a select box option on a product?
- How to check if a meta value has already been assigned to any user?
- function to assign user role based on a field from usermeta
- Creating user status mode in WordPress
- How to abort saving data in save_extra_profile_fields function WordPress?
- Update user profile information from functions.php
- Read array in php?
- Countdown to date function?
- If Array Values Match Another Array’s Values, Then
- Shortcode for Listing Users from Meta Value?
- Unable to Call More than One Meta Box Output
- Hide a div when a custom field is empty
- Uses for function: wp_update_user
- How to check post meta isset or not empty during publish/save post?
- Include User ID in iFrame URL
- WP custom posts: filter results to custom taxonomy tag that corresponds to user meta field
- Delete post meta by serialized meta value
- Display current user metadata on WordPress page
- How Can I Display the Last Modified Date for User Profiles on WordPress?
- Get user by meta data key and velue
- Where do I implement this display of User Meta Data, and how to put it in a table?
- Add another role to a user when they click a button?
- Store custom field’s multiple values in one user meta key
- Get field in readable word
- Adding user meta to post meta wp_insert_post() not working
- Private messaging – Getting and displaying the avatar/url of a message recipient
- Postmeta not saving
- Get author meta of all writers
- get_post_meta no longer working
- How to display the date under the post title?
- A better way to write this php function
- How do I get a function to work in single.php
- Need help setting default setting value for radio button in theme customizer
- How to automatically apply woocommerce product title to all product images alt tags?
- How to store the_title() into a variable to reutrn the value, not just echo it
- exclude multiple terms using get_terms() function
- Create a global variable for use in all templates
- Should the value of core functions be escaped before outputting?
- Why is my custom meta box input not saving
- Dynamic URL to reference custom PHP files
- WooCommerce – Customer Order History Pagination
- Change dns-prefetch to preconnect with correct protocol
- display most popular tags in two columns
- How to make thumbnail image fit into a div where image dimentions are completely different?
- Add before_content and after_content to register_sidebar
- How to access function from outside of a class within this class in WP plugin?
- Word Count Function Preventing Permalink Editing
- Using file_get_contents with Gravity Forms uploads folder to create images in the media library returning false
- Replace word in “the_content” only for index.php
- Auto-update products after they were published – Woocommerce
- How to VAR_DUMP a $variable during checkout process (Is my product meta callable?)
- get_post_meta not working on publishing
- php function to display commenter username or login
- How to change menu order item
- responsive.css in the WordPress should be prioritized
- How to display login form anywhere, when user isn’t logged in, without redirecting?
- Multiple meta_key in one global $wpdb;
- How to update and save user metadata on page visits?
- HTML Special Characters in URL string [closed]
- Create page template via functions.php?
- CSS change in woo commerce Place Order Text [closed]
- Getting different user data depending on where I use variable
- Comapare get_user_meta value
- How can get all users by current user meta?
- Add URL parameter to all internal links using a specific theme
- Warning: call_user_func() expects parameter 1 to be a valid callback, function
- Change MySQL PDO connection to a WPDB connection
- Post meta select input, if statement
- Modify WooCommerce used to get all orders in dashboard
- Can’t log in to WordPress wp-admin after adding code to functions.php
- How to change basename url for wp-admin?
- Run a sql (update) after 12 hours after the user login. Woocommerce users
- Wp_Schedule_Event every few minutes doesn’t work
- File from parent theme imported to child theme doesn’t work – any ideas?
- Problem with displaying CSS Stylesheets – Am I adding them correctly in my wordpress child theme?
- register_block_type is not working properly
- Store data from JavaScript object to custom table in user account
- cURL needing to loop through all “next_page”
- How to center all text body in single.php at once?
- Access WP files on “server 1”, from “server 2” – using wp-load on an external website
- How can I get my pagination loop to display the correct number of total pages?
- Stored meta from attachment, video length?
- How to include a function in a template with template tag
- wordpress all post filter by year
- Show post/page into div using function
- Pulling a variable into the wp_nav_menu function
- Popular Post Not Show
- WordPress – registering sidebar and adding a button directly after .textwidget
- If custom field doesn’t exist, or exists and it’s true show title?
- I am trying to replace a string with other from function.php
- Problem with function.php.. like
- Echo get_option displays as text
- Need help with Deprecated: Non-static error when update PHP 7.4 -> 8.1 with Dyad 2 theme
- posts_clauses drop ACF get_field function
- Show div only if product has attribute
- Is there a hook that I can use when a fatal error occurs?