Home > AI > Backend > Wordpress >

wp_insert_post_data

apply_filters( 'wp_insert_post_data', array $data, array $postarr, array $unsanitized_postarr )

Filters slashed post data just before it is inserted into the database.

The defaults for the parameter $data are:

'post_author',
'post_date',
'post_date_gmt',
'post_content',
'post_content_filtered',
'post_title',
'post_excerpt',
'post_status',
'post_type',
'comment_status',
'ping_status',
'post_password',
'post_name',
'to_ping',
'pinged',
'post_modified',
'post_modified_gmt',
'post_parent',
'menu_order',
'guid'

Example

/**
 * Use ID as title if title is empty
 */
add_filter("wp_insert_post_data", "st_fill_empty_title", 10, 2);
function st_fill_empty_title($data, $postarr) {
    $postid = $postarr["ID"];
    $title = $data['post_title'];
    if (empty($title)) {
        $data['post_title'] = $postid;
    }
    return $data;
}

Leave a Reply