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?

  • I am not sure about the above hook, can you try save_post instead and see if it works for you. – Maruti Mohanty Nov 20 '13 at 8:03
  • Thanks for the response I went for an alternative option see my answer below. – Nicodimos Nov 21 '13 at 21:44
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, privacy policy and cookie policy

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