0

コードを使用していくつかの静的ページを WP Web サイトにインポートしていますが、解決策が見つからない 2 つの問題があります。

これが私の挿入コードです:

$data = getPost(1);

// details for the post we're about to insert
$my_post = array(
    'post_title'  => $data['page_title'],
    'post_date'     => date('Y-m-d H:i:s',strtotime($data['date'])),
    'post_date_gmt' => date('Y-m-d H:i:s',strtotime($data['date'])),
    'post_content' => '<p>' . $data['intro'] . '</p>' . $data['body'],
    'post_status' => 'publish',
    //'post_category' => (!empty($cats[$data['category']]) ? $cats[$data['category']] :     1),
    'post_author' => (!empty($users[$data['author']]) ? $users[$data['author']] : 9),
    'post_name' => $data['slug'],
    'post_type' => 'post'
);

$data の中身が気になる場合は、次のとおりです。

Array ( [post_title] => Gutscheine bei Bingo3X gewinnen [post_date] => 2013-12-08 00:00:00 [post_date_gmt] => 2013-12-08 00:00:00 [post_content] => Nicht nur Geld gewinnen Macht Spaß, sondern Gutscheine können ebenfalls ihren Vorteil haben. So gibt es mit der Pouch-A-Vouch Aktion bei Bingo3X zurzeit Gutscheine im Wert von 30 £ gewinnen.

Nicht nur Geld gewinnen macht Spaß、sondern Gutscheine können ebenfalls ihren Vorteil haben. So gibt es mit der Pouch-A-Vouch Aktion bei Bingo3X zurzeit Gutscheine im Wert von 30 £ gewinnen.

[post_status] => 公開 [post_author] => 9 [post_name] => Gutscheine-bei-bingo3x-gewinnen [post_type] => post )

  1. http://codex.wordpress.org/Function_Reference/wp_insert_postによると、「post_name」は投稿のスラッグ(リンク)を作成します。このデータをインポートすると、投稿が正しく追加されますが、奇妙な番号がmysite.com/2013/10/08/gutscheine-bei-bingo3x-gewinnen-5 <--- その -5 はどこからともなく来ています..何かアイデアはありますか? :)

  2. もっと大きな問題。コード経由で Featured_image を追加するにはどうすればよいですか? URL を持っています (または、画像をローカルに配置できます。サイズはありますが、投稿に挿入する方法がわかりません。何らかの add_post_meta または wp_set_object_terms が役立ちますか? しかし、そこに何を書けばよいかわかりません。 ...

ありがとう!!

4

1 に答える 1

1
    if( null == get_page_by_title( $title_connection ) ) { 
// $title_connection should be unique

            $post_id = wp_insert_post(

                array(

                    'comment_status'    =>  'closed',

                    'ping_status'       =>  'closed',

                    'post_author'       =>  $author_id,

                    'post_name'         =>  $slug_connection,

                    'post_title'        =>  $title_connection,

                    'post_status'       =>  'publish',

                    'post_type'         =>  'page',

                    'post_parent'       =>  $page_parent->ID

                )

            );



        }

プログラムで投稿の注目の画像を挿入するには...

 $wp_filetype = wp_check_filetype(basename($filename), null );

    $attachment = array(
    'post_mime_type' => $wp_filetype['type'],
    'post_title' => preg_replace('/\.[^.]+$/', '', basename($filename)),
    'post_content' => '',
    'post_status' => 'inherit'
    );

    $attach_id = wp_insert_attachment( $attachment, $filename, $parent_id );
    $attach_data = wp_generate_attachment_metadata( $attach_id, $filename );
    wp_update_attachment_metadata( $attach_id, $attach_data );

add_post_meta($post_id, '_thumbnail_id', $attach_id, true);
于 2013-10-10T17:40:21.493 に答える