Must have both
The following arguments array searches for the post-type-slug videos
and category-slug video
. It doesn’t use pagination by setting posts_per_page
to -1 and only returns published posts.
$args = array(
'post_type' => 'videos',
'category_name' => 'video',
'posts_per_page' => -1,
'post_status' => 'publish'
);
Either this or that
If you are trying to show posts with EITHER the post-type OR the category slug, use two queries, because they are NOT combinable by any means of the arguments array.
$args = array(
'post_type' => 'videos',
'posts_per_page' => -1,
'post_status' => 'publish'
);
$args = array(
'category_name' => 'video',
'posts_per_page' => -1,
'post_status' => 'publish'
);
However, I am noticing that you are using query_posts()
. If you are trying to alter the main loop, please don’t. Use the pre_get_posts
hook instead. If you are querying this for a secondary loop, use WP_Query
instead.
With WP_Query
function create_slide() {
return '<li>
<a href="'. esc_attr( esc_url( get_the_permalink() ) ) .'">
<div class="tile-image">' . get_the_post_thumbnail('tile-small-thumb') . '</div>
<div class="tile-up-arrow"></div>
<div class="videoslider">Video</div>
<div class="tile-post-title">
<h5>' . get_the_title() . '</h5>
</div>
<div class="hover-display"></div>
</a>
</li>';
}
$slides = array();
$displayed = array();
$args = array(
'post_type' => 'videos',
'posts_per_page' => -1,
'post_status' => 'publish'
);
$query = new WP_Query( $args );
while ( $query->have_posts() ) : $query->the_post();
$displayed[] = get_the_ID();
$slides[] = create_slide();
endwhile;
$args = array(
'category_name' => 'video',
'posts_per_page' => -1,
'post_status' => 'publish',
'post__not_in' => $displayed,
);
$query = new WP_Query( $args );
while ( $query->have_posts() ) : $query->the_post();
$displayed[] = get_the_ID();
$slides[] = create_slide();
endwhile;
wp_reset_postdata();
echo implode('', $slides);