I have some trouble with regular wordpress functions in class methods
I save post meta like this and Its works fine:
public function saveMetadata( $postname ) {
$post_id = $_POST[ 'post_ID' ];
$post_holder = $_POST[ $postname ];
update_post_meta( $post_id, $postname, $post_holder );
}
But when i try update meta use same method, it doesnt work! why?
Thats i invoke this
//creation and run object
add_action( 'save_post', $quality->saveMetadata( 'project_quality' ) );
I had similar problem, I tried to update an order’s post meta in my class function with WP AJAX, but get_post_meta() worked, update not, so I solved it with deletetion of actual meta and add again new data, short example:
Try adding priority
add_action( 'save_post', $quality->saveMetadata( 'project_quality' ), 999 );
also, try checking the database table wp_postmeta to verify if there’s project_quality
I’ve having the same issue with update_post_meta functions but its because of Yoast SEO Field priority which I can’t figure out
This might help
update_post_meta for WordPress Yoast SEO
So, finally I solved this by using anonimous functions inside action, and send variable $post_id inside it.
It seems, wordpress expext id exacly from this var, strange but it works. Here the code:
Note: without any validation.
And invoke it, ofc: