コード9行目のID番号
連番なのでどんな数値が入るか分からない。
「int数値型で空の値を入れたらいいかな」と考えた。
で、’ ‘クォーテーションで囲わずに
‘ID’ => ,
としたらエラーになる。
文字列と同じに
‘ID’ => ”,
としたらイケた。
global $wpdb;
$poststable = $wpdb->prefix. 'posts';
$datetime = current_time( 'mysql' );
$gmttime = current_time( 'mysql', true );//第2引数のデフォルトはfalse(日本時間)。trueでgmt時間
$css = '.modal { display: none; } a[data-micromodal-trigger], button[data-micromodal-trigger] { pointer-events: none; opacity: 0.5; }';
$theme = get_stylesheet();
$data = array(
'ID' => '',//auto_incrimentで%dでも''で連番処理してくれる
'post_author' => 1,
'post_date' => $datetime,
'post_date_gmt' => $gmttime,
'post_content' => $css,
'post_title' => $theme,
'post_excerpt' => '',
'post_status' => 'publish',
'comment_status' => 'closed',
'ping_status' => 'closed',
'post_password' => '',
'post_name' => $theme,
'to_ping' => '',
'pinged' => '',
'post_modified' => $datetime,
'post_modified_gmt' => $gmttime,
'post_content_filtered' => '',
'post_parent' => 0,
'guid' => home_url( '/'. $theme. '/' ),
'menu_order' => 0,
'post_type' => 'custom_css',
'post_mime_type' => '',
'comment_count' => 0,
);
$format = array(
'%d', //ID
'%d', //post_author
'%s', //post_date
'%s', //post_date_gmt
'%s', //post_content
'%s', //post_title
'%s', //post_excerpt
'%s', //post_status
'%s', //comment_status
'%s', //ping_status
'%s', //post_password
'%s', //post_name
'%s', //to_ping
'%s', //pinged
'%s', //post_modified
'%s', //post_modified_gmt
'%s', //post_content_filtered
'%d', //post_parent
'%s', //guid
'%d', //menu_order
'%s', //post_type
'%s', //post_mime_type
'%d', //comment_count
);
$wpdb->insert( $poststable, $data, $format );
コメントを残す