WordPress.org

Ready to get started?Download WordPress

Forums

Subscribe2
Subscribe2 and Custom Fields (5 posts)

  1. ip027
    Member
    Posted 2 years ago #

    Why can not I select from the database meta data to be inserted in the message body?

    example1 subscribe2.php in function substitute($string = '', $post_ID):

    ...
    $sent = get_post_meta($post_ID, 'my_meta', true);
    ...
    $string = str_replace("{TITLE}", stripslashes($sent), $string);
    ...

    $post_ID passed to the function. Dont work, $sent is empty

    example2 subscribe2.php in function substitute($string = '', $post_ID):

    ...
    $results = $wpdb->get_results("SELECT meta_key, meta_value FROM wp_postmeta WHERE post_id = $post_ID");
    foreach ($results as $result){
    ......
    }
    ...
    $string = str_replace("{TITLE}", stripslashes($sent), $string);
    ...

    Dont work, $sent is empty

    selecting only: edit_lock, s2mail, _edit_last
    Why can not retrieve other metadata?

    http://wordpress.org/extend/plugins/subscribe2/

  2. mattyrob
    Member
    Plugin Contributor

    Posted 2 years ago #

    @ip027,

    Instead of using $post_id, try using the $post object.

    global $post;
    $sent = get_post_meta($post->ID, 'my_meta', true);
  3. ip027
    Member
    Posted 2 years ago #

    tried, with this design started. $sent is empty.
    But if write
    $sent = get_post_meta($post->ID, 's2mail', true);
    it's work: $sent = 'yes' or 'no'

  4. mattyrob
    Member
    Plugin Contributor

    Posted 2 years ago #

    @ip027,

    Okay, so at least you have the get_post_meta() function working. What other keys are you looking for? Are you sure that they are actually in the postmeta table? Have you checked that table using PHPMyAdmin or similar to see what values are present?

  5. ip027
    Member
    Posted 2 years ago #

    it works! to get the metadata in a letter, you must first save the meta data and then publish the post. It seems that when you publish a post function to send a letter (subscribe2) is called before the insert function of meta data.

    MattyRob, Thanks for your help!

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic