自定义日期php wordpress自动发布

时间:2015-01-13 05:08:19

标签: php wordpress post

当我从wp_media上传图片时,以下代码运行:

add_action('add_attachment', 'auto_post_after_image_upload'); // Wordpress Hook

function auto_post_after_image_upload($attachId)
{
    $attachment = get_post($attachId);
    $image = wp_get_attachment_image_src( $attachId, 'large');
    $image_tag = '<p><img src="'.$image[0].'" /></p>';

    $postData = array(
        'post_title' => $attachment->post_title,
        'post_type' => 'post',
        'post_content' => $image_tag . $attachment->post_title,
        'post_category' => array('0'),
        'post_status' => 'publish',
        'post_date' => get_the_time()
    );

    $post_id = wp_insert_post($postData);

    // attach media to post
    wp_update_post(array(
        'ID' => $attachId,
        'post_parent' => $post_id,
    ));

    set_post_thumbnail($post_id, $attachId);

    return $attachId;
}

现在我想在创建图像时输入图像的日期而不是今天的日期。我怎样才能做到这一点? get_the_time()返回今天的日期。我希望所选图像创建日期。

<code>Created date from image properties</code>

1 个答案:

答案 0 :(得分:0)

您可以使用此php函数exif_read_data