• 解決済 kaerujp

    (@kaerujp)


    1.投稿ページで指定カスタム投稿タイプの指定カテゴリのみ表示させたいのですがうまくいきません。。。

    ■カスタム投稿のカテゴリ指定表示

    <?php
    global $post;
    $args = array(
      'posts_per_page' => 4,
      'post_type'=> 'price',
      'terms' => 'gold',
    );
    $myposts = get_posts( $args );
    foreach ( $myposts as $post ) : setup_postdata( $post ); ?>
      <dl class='news'>
        <dt class='news-title'><?php the_title(); ?></dt>
        <dd class='news-date'><?php the_date('Y.m.d'); ?></dd>
        <dd class='news-content'><?php the_content(); ?></dd>
      </dl>
    <?php
    endforeach;
    wp_reset_postdata();
    ?>

    また、現在のページで自動的にカテゴリを取り込み自動的にカテゴリのみのリストを表示したいのですが、そちらもうまくいかない形です…

    <?php
    global $post;
    $args = array(
      'posts_per_page' => 4,
      'post_type'=> 'price',
      'terms' => array( $post->post_name ),
    );
    $myposts = get_posts( $args );
    foreach ( $myposts as $post ) : setup_postdata( $post ); ?>
      <dl class='news'>
        <dt class='news-title'><?php the_title(); ?></dt>
        <dd class='news-date'><?php the_date('Y.m.d'); ?></dd>
        <dd class='news-content'><?php the_content(); ?></dd>
      </dl>
    <?php
    endforeach;
    wp_reset_postdata();
    ?>
     
    <?php endif; wp_reset_postdata(); ?>

    いろんなページを見たのですが、、なかなかうまくいかず、、、

2件の返信を表示中 - 1 - 2件目 (全2件中)
  • こんにちは

    カテゴリー名 (スラッグ) なら category_name ではないでしょうか?

    'terms' => 'gold',
    

    'category_name' => 'gold',

    カスタム タクソノミーの場合は、

    'tax_query' => array(
    	array(
    		'taxonomy' => 'カスタム タクソノミー',
    		'field'    => 'slug',
    		'terms'    => 'gold',
    	)
    ),
    トピック投稿者 kaerujp

    (@kaerujp)

    ありがとうございます!

    category_nameで表示されました!

2件の返信を表示中 - 1 - 2件目 (全2件中)
  • トピック「カスタム投稿タイプのカテゴリでの絞込」には新たに返信することはできません。