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
- get_*_meta doesn’t always return an array
- Calling directories to load in wordpress
- WordPress add post format support not working
- Can I prevent the user from adding more than two levels deep of terms inside of a taxonomy metabox?
- Image media upload metabox
- How to remove the cufon script from Dzonia Lite theme [closed]
- How to remove or change the “W” icon in “My Sites”?
- get a simple array of all of the term names that exist in all taxonomies
- Login/logout in header
- How to display posts by current user in a drop down
- Logged in user ID as post ID
- How does WordPress insert Paragraphs in posts
- WordPress Access allowed to fewer pages till user logs in
- Linking text within textarea of custom meta box
- Show css depending on activity type in BuddyPress activity-loop [closed]
- only show container with next/prev links if they exist?
- How to combine wordpress_logged_in cookies in one cookie?
- Populate dropdown with Child Pages based on Parent Page chosen
- How can I remove a function that has been added to wordpress with add_filter?
- Change the WP Video Shortcode Output
- Show categories then when clicked on a category list all sub category and when clicked show all posts in that sub category
- remove wp floating submenu in wp dashboard
- How to put “Read more” link in Custom Excerpt inside p tag?
- Two Different Links for Same Product – WooCommerce [closed]
- ACF: how do I get the fields and its values of a specific group?
- How to store data from multiple forms using ajax and php
- How to control WordPress image metadata (using Imagick)?
- How to add seperate classes to no-search-result and found-search-result pages on wordrpess search – is_search()
- Get value from shortcode to do something
- PHP 8, AJAX mail form to function.php doesn’t work
- How do I add custom bulk actions to multiple custom post types?
- Error when adding excerpt to the content through functions.php
- Automatically adding new post categories to menu
- Add data attribute to each li in menu
- Get post id in a function when edit/add a post
- Making BuddyPress Activity Stream (Post Type) Featured Images Clickable [closed]
- How to complete two other input fields, completed the first
- Prev/Next child navigation for current page modifications?
- Adding rel tag to all external links
- Sort custom meta column by other meta value
- adding custom user input fields in WordPress admin dashboard gives error The link you followed has expired. Please try again
- How can I apply_filters from inside a function?
- what is the best practice to add new field to an api route
- Retrieve $_POST data submitted from external URL in WordPress(NOT API)
- Store multiple custom field as post meta per post(css, js, html, 2 link) [closed]
- How to upload a file to a folder named after the user_id via plugin
- Pass Category Name, Description and Photo into variables to pass to jQuery
- Use DOMDocument with ob_start breaks my HTML code
- Auto-update products after they were published – Woocommerce
- How to prevent WP_Query function from returning all posts when empty?
- How to VAR_DUMP a $variable during checkout process (Is my product meta callable?)
- wp_trim_words() does not work with my code Am I doing any mistake in my code?
- JS file work only in index page
- Display a specific category of products in shop page and disable code for specific actions
- Woocommerce related product text
- esc_html_e() is not translating string in wordpress [closed]
- Removing “wpautop” (auto tags) only on certain pages?
- Fatal error: Uncaught Error: Call to undefined function test()
- How to pick the default selected value in wordpress dropdown?
- get_post_meta not working on publishing
- Using WP-API and SSE not authenticating user ID
- Need help with Google drive API [closed]
- Woocommerce: hook action/filter I could use to add variation id and price with each attribute opt on WooCommerce Rest api
- Validate functions before inserting then into functions.php