最新記事にカスタム投稿タイプを表示させる。【wordpress】



久々に、wordpressをいちから構築していく上で忘れている事が多すぎる。
ということで、久々にwordpressの記事を更新する。

まずは、カスタム投稿タイプを最近の投稿(新着記事)に表示させる方法

以下のコードを functions.phpに書き込めばOK

[php]
//最新記事にカスタム投稿タイプを含める
function chample_latest_posts( $wp_query ) {
if ( is_home() && ! isset( $wp_query->query_vars['suppress_filters'] ) ) {
$wp_query->query_vars['post_type'] = array( 'post', 'page','xxxxxx','xxxxxx' );
}}
add_action( 'parse_query', 'chample_latest_posts' );
[/php]

array( 'post', 'page','xxxxxx','xxxxxx' );
「xxxxx」の部分に新着記事に表示させるカスタム投稿のスラグをいれす。

postは通常の「投稿」で「page」は固定ページなので、不要な場合は削除。



53/100

ああああ