ビジュアルエディタに入力したテキストや画像はRSSフィード(feed)で発信できる。しかしながら、カスタムフィールドの値や、ギャラリー機能を使用するために登録した添付画像(アタッチメント)はフィードには含まれない。デフォルトでは。
カスタムフィールドの値や添付(アタッチメント)をフィードに含めるには:
the_excerpt_rss と the_content_feed をフックして”追加したい内容”を$contentに追加してはきだせばよい。
functions.phpに次のように記述
function my_feeds($content) { global $post; $content = $content. "追加したい内容を記述"; // return $content; } add_filter('the_excerpt_rss', 'my_feeds'); add_filter('the_content_feed', 'my_feeds');
これを基本として、”追加したい内容を記述” の部分がカスタムフィードの値や添付の情報になればよいので、
例えば、添付画像の場合は(カスタムフィールドも同様のロジックで可能)
function my_feeds($content) { global $post; $imgThum = ""; $postid = $post->ID; $args = array( 'numberposts' => 1,//添付画像を1枚取得する場合(初期値は5件、-1で全添付を取得) 'order' => 'ASC',//並び順 'orderby' => 'menu_order',//並び順の規準 'post_type' => 'attachment',//取得種類(この指定で添付を取得できる) 'post_mime_type' => 'image',//取得種類(この指定で添付の種類ギャラリーを取得できる) 'post_parent' => $postid//帰属する投稿ID ); $attachments = get_posts( $args ); if ( $attachments ){ foreach ( $attachments as $attachment ) { $imgThum = wp_get_attachment_image( $attachment->ID, 'thumbnail' );//thumbnail, medium, large, full break; } if($imgThum != "") $content = '<div class="img">' . $imgThum . '</div>' . $content; return $content; } add_filter('the_excerpt_rss', 'my_feeds'); add_filter('the_content_feed', 'my_feeds');