WordPress.org

Support

Support » Plugins and Hacks » Subscribe2 » Advanced Custom Fileds in mail body are empty

Advanced Custom Fileds in mail body are empty

Viewing 7 replies - 1 through 7 (of 7 total)
  • @dobst,

    Subscribe2 uses the WordPress post transition hooks to trigger the email notification events. Unfortunately the calls to create or update post meta data happen after this so essentially if you post directly the Subscribe2 events are triggered before the custom fields exist. You need to save first to create the meta before hitting publish.

    Hello Matty, thank you for your reply. How can I achieve this? Custom fields are “begin_date” and “end_date”. I tried to force a “save” before publishing with the following, various actions in my functions.php:

    function save_details() {
     global $post;
     update_post_meta($post->ID, "begin_date", $_POST["begin_date"]);
     update_post_meta($post->ID, "end_date", $_POST["end_date"]);
     add_post_meta($post->ID, 'begin_date', $_POST["begin_date"], false);
     add_post_meta($post->ID, 'end_date', $_POST["end_date"], false);
    }
    add_action('pre_post_update', 'save_details');
    add_action('before_publish_post', 'save_details');

    But it doesn’t work.

    @dobst,

    The ‘pre_post_update’ hook only fires if content is being updated, if you are immediately publishing then it won’t be an update.

    I cannot find a ‘before_publish_post’ hook at all.

    Maybe try using the ‘transition_post_status’ hook or have a look through the wp-includes/post.php file for a more appropriate hook.

    Ok, thank you for the hint. There is a bunch of transiton_post_status hooks. But non works 🙁 Hope, the function save_details() is correct:

    function save_details() {
     global $post;
     update_post_meta($post->ID, "begin_date", $_POST["begin_date"]);
     update_post_meta($post->ID, "end_date", $_POST["end_date"]);
     add_post_meta($post->ID, 'begin_date', $_POST["begin_date"], false);
     add_post_meta($post->ID, 'end_date', $_POST["end_date"], false);
    }
    add_action('new_to_publish', 'save_details');
    add_action('pending_to_publish', 'save_details');
    add_action('draft_to_publish', 'save_details');
    add_action('auto-draft_to_publish', 'save_details');
    add_action('future_to_publish', 'save_details');
    add_action('private_to_publish', 'save_details');
    add_action('trash_to_publish', 'save_details');

    @dobst,

    Those are the exact same hooks that Subscribe2 uses so your code may still get called after Subscribe2. The way to ensure your code is called first is by using the priority parameter of the add_action() function.

    Maybe try something like:
    add_action('new_to_publish', 'save_details', 5);

    Mh, I tried to raise the priority (lower the value) without an effect.

    @dobst,

    I think you may need to examine the contents of $_POST more closely. The meta files are contained in $_POST[‘meta’] and it’s a nested array with ‘key’ and ‘value’ pairs. I suspect the issue is because variables like $_POST[“begin_date”] will be undefined.

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Advanced Custom Fileds in mail body are empty’ is closed to new replies.
Skip to toolbar