trying to show custom post type specific custom ca

2019-08-01 02:37发布

i have a custom post type category and its name is donations and donations category has 50 posts. now i want to fetch all those posts any help?

i want to show on template page, name is /Template Name: Help Donations/

i try all of this but its not working for me.

<?php query_posts('category_name=donations&post_type=help'); ?>

    <?php while(have_posts()): the_post(); ?>

    <?php the_title(); ?>

    <?php endwhile; ?>

<?php wp_reset_query(); ?>

also this one too is not working.

<?php $the_query = new WP_Query('category_name=donations&post_type=help'); ?>

    <?php while($the_query->have_posts()): $the_query->the_post(); ?>

    <?php the_title(); ?>

    <?php endwhile; ?>

<?php wp_reset_postdata(); ?>

标签: wordpress
1条回答
家丑人穷心不美
2楼-- · 2019-08-01 03:12

Try this. You may need to change the taxonomy name. I just assumed that you named it post_type_category. So this is to get all post_types with the name help that has the post_type_category with the name donations.

$args = array( 'post_type' => 'help',
               'tax_query' => array(
                      array(
                      'taxonomy' => 'post_type_category', //don't know if this is right for you
                      'field' => 'slug',
                      'terms' => 'donations'
                      )
                )
            );
$loop = new WP_Query( $args );
while ( $loop->have_posts() ) : $loop->the_post();
  the_title();
  echo '<div class="entry-content">';
  the_content();
  echo '</div>';
endwhile;
查看更多
登录 后发表回答