wordpress show posts from post type and cat using slug
I am trying to show posts from the ‘faq’ custom post type that are tagged with the category name of the page your on. for example if you are on the ‘family’ page it should show all faq’s tagged with the category ‘family’. the only way it can do this is by using the url slug as i have many category’s and pages. here is my code so far but this shows all posts from the post type.
<?php $slug = preg_replace('/\s+/', '', $post->post_name); ?> <?php $loop = new WP_Query( array( 'post_type' => 'faq', 'cat' => $slug, 'posts_per_page' => 5, 'orderby' => 'date', 'order' => 'DESC' ) ); while ( $loop->have_posts() ) : $loop->the_post(); ?> <div class="related-faq"> <a href="<?php the_permalink(); ?>"><?php echo wp_trim_words( get_the_title(), 5 ); ?></a> </div>
- The topic ‘wordpress show posts from post type and cat using slug’ is closed to new replies.