Display only posts from a specific category or post type
-
I am not certain what I have wrong. I just need to display the posts from a custom post type and/or a single category.
I have a custom post type called “videos” that I want to display the posts from outside the basic loop. That loop is already displaying properly on the page. However, when this loop is reached, it displays all of the Posts again, but it does not include this custom post type at all. It’s showing every post I do not want instead of the ones that I do.
I have tried to use the same code to filter by category (the default WordPress categories, not a custom taxonomy) and it does not work in that way either.
<?php // The Query $the_query = new WP_Query( array( 'post_type' => 'videos' ) ); // The Loop if ( $the_query->have_posts() ) { echo '<ul>'; while ( $the_query->have_posts() ) { $the_query->the_post(); echo '<li>' . get_the_title() . '</li>'; } echo '</ul>'; } else { echo("Broken"); } /* Restore original Post Data */ wp_reset_postdata(); ?>
Viewing 3 replies - 1 through 3 (of 3 total)
Viewing 3 replies - 1 through 3 (of 3 total)
- The topic ‘Display only posts from a specific category or post type’ is closed to new replies.