サポート » 使い方全般 » 2つのカスタム投稿タイプと特定タームでの一覧

  • カスタム投稿(info)と別のカスタム投稿(menu)のターム(orange)を
    一緒の一覧に表示したく苦戦しております。

    1)カスタム投稿:info
    ※タクソノミー、タームなし

    2)カスタム投稿:menu
    タクソノミー:drink
    ターム:orange、appleなど

    上記条件にて、日付順で最新記事10件を取得したいです。
    それぞれ個別の取得は下記で可能でした。

    カスタム投稿:info

    <?php
    $args = array(
    	'post_type' => array('info'),
    	'orderby' => 'date',
    	'posts_per_page' => 5
    	);
    ?>
    <?php
    $custom_query = new WP_Query( $args );
    if ( $custom_query->have_posts() ):
    while ( $custom_query->have_posts() ) :	$custom_query->the_post();
    ?>
    <p><?php the_time('Y年m月j日'); ?> <a href="<?php the_permalink() ?>"><?php the_title(); ?></a></p>
    <?php endwhile; endif; ?>
    <?php wp_reset_query(); ?>

    カスタム投稿:menuのターム:orange

    <?php
    $args = array(
    'post_type' => 'menu',
    'taxonomy' => 'drink',
    'term' => 'orange',
    'posts_per_page' => 5,
    'numberposts' => '-1',
    );
    $my_posts = get_posts($args);
    foreach ( $my_posts as $post ) {
    setup_postdata($post); ?>
    <p><?php the_time('Y年m月j日'); ?> <a href="<?php the_permalink() ?>"><?php the_title(); ?></a></p>
    <?php
    }
    ?>

    これをどう、一緒に一覧にして、日付順で10件取得したら良いか悩んでおります。
    どうぞ宜しくお願い致します。

1件の返信を表示中 - 1 - 1件目 (全1件中)
  • トピック投稿者 watermusic

    (@watermusic)

    色々調べて、
    複数のカスタム投稿タイプと属する複数のタームを表示
    というやり方まではたどり着いたのですが
    私の場合は、片方のカスタム投稿(info)には
    タクソノミーもタームもないので、つまづきました。

    <?php
    $args = array(
        'post_type' => array('カスタム投稿タイプA','カスタム投稿タイプB'),
        'tax_query' => array(
                array(
                    'taxonomy' => 'カスタムタクソノミーA',
                    'field' => 'slug',
                    'terms' => array( 'タームA1', 'タームA2' ),
                    ),
                array(
                    'taxonomy' => 'カスタムタクソノミーB',
                    'field' => 'slug',
                    'terms' => array( 'タームB1', 'タームB2' ),
                    ),
                'relation' => 'OR'
                )
            );
    $the_query = new WP_Query( $args );
    ?>
1件の返信を表示中 - 1 - 1件目 (全1件中)
  • トピック「2つのカスタム投稿タイプと特定タームでの一覧」には新たに返信することはできません。