固定ページに特定のカスタム分類のタームに属する投稿一覧を表示させるショートコード
かなり個人用途なのでぼかさず記録。
カスタム投稿タイプ:books2
カスタム分類:ffcat
カスタム分類のターム:gensui3
カスタムフィールド名:couple
のとき、functions.phpに以下を記載する。
function sc_exliste($atts, $content = null) { extract(shortcode_atts(array( "excat" => '' ), $atts)); global $post; $args = array( 'numberposts' => -1, 'order' => 'DESC', 'orderby' => 'post_date', 'post_type' => 'books2', 'ffcat' => $excat ); $itemlist = get_posts($args); $retour='<dl class="item_list">'; foreach($itemlist as $post) : setup_postdata($post); $retour .= '<dt><a href="'.get_permalink().'">'.the_title("","",false).'</a></dt>'; $retour .= '<dd class="item_cp">' . get_field('couple') . '</dd>'; $retour .= '<dd class="item_date">' . get_the_date('Y.m.d') . '</dd>'; endforeach; $retour.='</dl> '; return $retour; } add_shortcode("feed", "sc_exliste");
呼び出すショートコードは
[feed excat="gensui3"]
ひとつの固定ページ内に複数設置しても大丈夫なことは確認済です。
固定ページにショートコードを挿入させるのの焼き直し。