简体   繁体   中英

Filter & display Custom Post Type posts by their assigned catagories?

I have a Custom Post Type called 'Services', it's slug is called 'services'. And as displayed in this image, they all have their own assigned categories.

我的“服务”帖子类型带有类别。

How do I go about writing a WP_Query/loop that displays the titles of all 'Services' with the category 'Face'? (With a hyperlink to their respective pages also.)

Below is code that will achieve the result you want

$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; ?>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM