Quantcast
Channel: WordPress › Support » Forum: Hacks - Recent Topics
Viewing all articles
Browse latest Browse all 8245

Vajrasar Goswami on "save_post not working"

$
0
0

In order to create (or update, whenever a post is updated) a unix-timestamp meta, I used following code to fire on save_post. I pasted this code in functions.php.

But I believe this is not working, as I can't access the related unix meta created by save_post in loop anywhere in a custom template.

Code -

function vg_update_timestamp( $post_id ) {

    $offerstartdate = get_post_meta($post_id, 'offer_cmb_offer_from_textdate', true); //not unix timestamp
    $offerenddate =  get_post_meta($post_id, 'offer_cmb_offer_till_textdate', true);  //not unix timestamp

    $timestamp_start = strtotime( $offerstartdate );
    $timestamp_end = strtotime( $offerenddate );

    update_post_meta($post_id, 'offer_cmb_offer_from_textdate_unix', $timestamp_start );
    update_post_meta($post_id, 'offer_cmb_offer_till_textdate_unix', $timestamp_end );
}
add_action( 'save_post', 'vg_update_timestamp' );

Viewing all articles
Browse latest Browse all 8245

Trending Articles