按分配的类别过滤和显示“自定义帖子类型”帖子?

时间:2018-07-25 10:22:00

标签: php html wordpress filter custom-post-type

我有一个自定义帖子类型,称为“服务”,它的子句称为“服务”。如该图所示,它们都有自己分配的类别。

My 'Services' post type with categories.

如何编写一个WP_Query / loop来显示类别为“ Face”的所有“服务”的标题? (还具有指向各自页面的超链接。)

1 个答案:

答案 0 :(得分:1)

下面是将实现所需结果的代码

$args = array(
    'post_type' => 'services',
    'category'    => 'Face',
);
$loop = new WP_Query( $args );
if ( $loop->have_posts() ) : 
  while ( $loop->have_posts() ) : $loop->the_post(); ?>
    ----Here will be your html in which format you want to display your title-----
    <p><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></p>
  <?php endwhile; 
endif; ?>