• 解決済 layperson

    (@layperson)


    twentyfourteenに子テーマを作ってカスタマイズしています。
    フィーチャードエリアにCustom Post Type UIで設定したカスタム投稿記事を反映させたいです。
    以前フォーラムにありました→https://ja.forums.wordpress.org/topic/117876?replies=6 のページを参考にしましたが、表示されません。

    子テーマに親テーマの『inc/featured-content.php』をコピペして設置しています。以前のフォーラムのコードと少し変わっているように思うのですが、”’post_type’ => array(‘post’, ‘myposttype’)”を記述する位置が間違っているのでしょうか。
    inc/featured-content.phpの160行目あたりのコードにこのように追加しました。↓

    if ( $term ) {
    				// Query for featured posts.
    				$featured_ids = get_posts( array(
    					'post_type' => array('post', 'myposttype'),
    					'fields'           => 'ids',
    					'numberposts'      => self::$max_posts,
    					'suppress_filters' => false,
    					'tax_query'        => array(
    						array(
    							'field'    => 'term_id',
    							'taxonomy' => 'post_tag',
    							'terms'    => $term->term_id,
    						),
    					),
    				) );
    			}

    WordPressは手探りでphpを触るレベルです。
    よろしくお願いいたします。

2件の返信を表示中 - 1 - 2件目 (全2件中)
  • Twenty Fourteen のバージョン 1.5 の場合は二箇所に追加する必要があります。ひとつはlaypersonさんが追加したところ、もうひとつは同じ featured-content.php の131行目に出てくるget_postsです。こちらにも同じように投稿タイプを指定します。

    オリジナル:

    $featured_posts = get_posts( array(
    	'include'        => $post_ids,
    	'posts_per_page' => count( $post_ids ),
    ) );

    追加後(この例は myposttype を追加):

    $featured_posts = get_posts( array(
    	'post_type'      => array( 'post', 'myposttype' ),
    	'include'        => $post_ids,
    	'posts_per_page' => count( $post_ids ),
    ) );

    トピック投稿者 layperson

    (@layperson)

    gblsmさん

    ありがとうございます!
    Twenty Fourteenのバージョンは1.5でした。
    教えていただいた通りに追加しましたら表示されました!
    何週間もここで頭を抱えていましたので本当に助かりました。
    ありがとうございます。

2件の返信を表示中 - 1 - 2件目 (全2件中)
  • トピック「twentyfourteenのフィーチャードエリアにカスタム投稿記事を表示させたい」には新たに返信することはできません。