• 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/

Viewing 4 replies - 1 through 4 (of 4 total)
  • @ip027,

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

    global $post;
    $sent = get_post_meta($post->ID, 'my_meta', true);
    Thread Starter ip027

    (@ip027)

    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’

    @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?

    Thread Starter ip027

    (@ip027)

    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!

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Subscribe2 and Custom Fields’ is closed to new replies.