1

So I have a little function that runs successfully in with publish_post. This is the code:

function socialOverlay( $ID, $post ) {
    $name = 'myname';
    $email = 'myname@gmail.com';
    $to[] = sprintf( '%s <%s>', $name, $email );
    $subject = 'test';
    $headers[] = '';
    $updateRet = update_post_meta( $ID, "_yoast_wpseo_opengraph-image", "a_valid_image_url");
    $message = print_r( $ID, true ) . "\n\n";
    $message .= print_r( $post, true ) . "\n\n";
    $message .= print_r( $updateRet, true ) . "\n\n";
    wp_mail( $to, $subject, $message, $headers );
}

add_action( 'publish_post', 'socialOverlay', 10, 2 );

The code runs, and I get an email with the prints. What i get is this:

3310

WP_Post Object
(
    [ID] => 3310
    [post_author] => 1
    [post_date] => 2018-07-15 09:46:43
    [post_date_gmt] => 2018-07-15 06:46:43
    [post_content] => test8a
    [post_title] => test 8
    [post_excerpt] => 
    [post_status] => publish
    [comment_status] => closed
    [ping_status] => closed
    [post_password] => 
    [post_name] => test-8
    [to_ping] => 
    [pinged] => 
    [post_modified] => 2018-07-15 09:46:43
    [post_modified_gmt] => 2018-07-15 06:46:43
    [post_content_filtered] => 
    [post_parent] => 0
    [guid] => http://mysite.loc/?p=3310
    [menu_order] => 0
    [post_type] => post
    [post_mime_type] => 
    [comment_count] => 0
    [filter] => raw
)


81504

However when I search in database, there is no entry in the "postmeta" table with the "81504" meta_id and of course no change to the actual html source code in the published post.

Any ideas what I am doing wrong here?

  • It looks OK. Are you sure that this meta isn't removed later on by some plugin? – Krzysiek Dróżdż Jul 15 '18 at 7:43
  • Yes you are right, it is removed later indeed – odorf Jul 15 '18 at 7:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.