記事を投稿した時に、同じ内容の記事をプログラムが複製し新しく公開するプログラムを作っています。
ですが、タグとカテゴリーを複数選択した時に、プログラムで作られた記事は、1つしか表示されない状態です。
「$get_tag[0]->name」←の記述で、[0]を取っても複数表示することが出来ませんでした。
どのような記述で、複数選択したタグとカテゴリーをプログラムで作った記事に追加することができるのでしょうか?
function get_news() { global $post; $get_title = $post->post_title; //記事タイトル取得 $get_content = $post->post_content; //記事本文取得 $get_tag = get_the_tags(); //記事タグ取得 foreach ($get_tag as $tag) { $get_tag_id = $get_tag[0]->name.','; } $get_category = get_the_category(); //記事カテゴリー取得 $get_category_id = $get_category[0]->cat_ID; $my_post = array( 'post_type' => 'post', //投稿タイプ 'post_title' => $get_title, //記事タイトル 'post_status' => 'publish', //投稿ステータス 'post_content' => $get_content, //記事本文 'post_category' => array($get_category_id), //記事カテゴリー 'tags_input' => array($get_tag_id) //タグ ); remove_action('publish_post', 'get_article_created_time'); //無限loop解除用 $post_id = wp_insert_post($my_post); add_action('publish_post', 'get_article_created_time'); } add_action('publish_post', 'get_news'); //記事の更新と公開した時のアクションフック
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
退会済みユーザー
2017/11/20 01:04