0

I'm trying to get the user_meta to be updated based on the custom post field type. However the information won't transfer if the new post is published by a user through a frontend form.

Currently it only works if you update a listing via the front end form, or publish/edit a post via the backend of wordpress.

function update_package_id($post_id) {
$post = get_post($post_id);
$author = get_userdata($post->post_author);
$author_email = $author->user_email;
$package_id = get_post_meta( $post->ID, 'package_pid', true  );
$user_id = $author->ID;
update_user_meta($user_id, 'package_type', $package_id);

if (function_exists( 'AC_OnUpdateUser' )) {
$user = new WP_User( $user_id );
AC_OnUpdateUser( $user->ID, $user, FALSE );
}
}

add_action( 'publish_place', 'update_package_id' );

The second function fires the information into mailchimp. Am I using the wrong action in wordpress?

2
  • I am not sure about the above hook, can you try save_post instead and see if it works for you. Commented Nov 20, 2013 at 8:03
  • Thanks for the response I went for an alternative option see my answer below.
    – Nicodimos
    Commented Nov 21, 2013 at 21:44

1 Answer 1

0

So the theme I used was not firing add_action( 'publish_place', 'update_package_id' ); or any of it's variations e.g. save_post

So I created a custom hook in the functions.php file of the theme which got the post id from the url (see $_REQUEST['pid']) here's what it looked like:

function update_package_id() {
$postinfo = $_REQUEST['pid'];
$post = get_post($postinfo);
$author = get_userdata($post->post_author);
$author_email = $author->user_email;
$package_id = get_post_meta( $post->ID, 'package_pid', true  );
$user_id = $author->ID;
update_user_meta($user_id, 'package_type', $package_id);

if (function_exists( 'AC_OnUpdateUser' )) {
$user = new WP_User( $user_id );
AC_OnUpdateUser( $user->ID, $user, FALSE );
}} add_action( 'updateusermet', 'update_package_id' ); 

This was then called through do_action('updateusermet'); on the post submitted success page at the bottom before get_sidebar();

I hope that helps someone

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.