Skip to main content
Tweeted twitter.com/#!/StackWordPress/status/291757542336499713

How can I query all the posts from either the custom post type ('videos') or with a post category ('video') in a loop?

I've managed to create a query that combines the posts from a custom post type and the normal posts using the code below, but am struggling with achieving the same with a custom post type and a post category.

<?php $args = array_merge( $wp_query->query, array( 'post_type' => array( 'post', 'videos', ) ) ); query_posts( $args ); ?>     
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>

Any help would be appreciated!

This is what my slides look like:

if($query->have_posts()){
while ( $query->have_posts() ) {
    $query->the_post();
    $carousel_slide = '<li>
               <a href="<?php the_permalink(); ?>">
               <div class="tile-image"><?php the_post_thumbnail('tile-small-thumb'); ?></div>
               <div class="tile-up-arrow"></div>
               <div class="videoslider">Video</div>
               <div class="tile-post-title">
                   <h5><?php the_titlesmall('', '...', true, 55); ?></h5>
               </div>
               <div class="hover-display" ></div>
               </a>
           </li>';
    $found_posts[] = $post->ID;
    $slides[] = $carousel_slide;
}
wp_reset_postdata();

}

First off, I get a Parse error: syntax error, unexpected T_STRING on <?php the_post_thumbnail('tile-small-thumb'); ?> and a Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING on <h5><?php the_titlesmall('', '...', true, 55); ?></h5>. Removing these loads the page fine, but doesn't render the links as links, but instead as <?php the_permalink(); ?>.

If I'm just doing everything wrong here please let me know and I'll go ahead and close this question.

Thanks again for you time.

How can I query all the posts from either the custom post type ('videos') or with a post category ('video') in a loop?

I've managed to create a query that combines the posts from a custom post type and the normal posts using the code below, but am struggling with achieving the same with a custom post type and a post category.

<?php $args = array_merge( $wp_query->query, array( 'post_type' => array( 'post', 'videos', ) ) ); query_posts( $args ); ?>     
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>

Any help would be appreciated!

How can I query all the posts from either the custom post type ('videos') or with a post category ('video') in a loop?

I've managed to create a query that combines the posts from a custom post type and the normal posts using the code below, but am struggling with achieving the same with a custom post type and a post category.

<?php $args = array_merge( $wp_query->query, array( 'post_type' => array( 'post', 'videos', ) ) ); query_posts( $args ); ?>     
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>

Any help would be appreciated!

This is what my slides look like:

if($query->have_posts()){
while ( $query->have_posts() ) {
    $query->the_post();
    $carousel_slide = '<li>
               <a href="<?php the_permalink(); ?>">
               <div class="tile-image"><?php the_post_thumbnail('tile-small-thumb'); ?></div>
               <div class="tile-up-arrow"></div>
               <div class="videoslider">Video</div>
               <div class="tile-post-title">
                   <h5><?php the_titlesmall('', '...', true, 55); ?></h5>
               </div>
               <div class="hover-display" ></div>
               </a>
           </li>';
    $found_posts[] = $post->ID;
    $slides[] = $carousel_slide;
}
wp_reset_postdata();

}

First off, I get a Parse error: syntax error, unexpected T_STRING on <?php the_post_thumbnail('tile-small-thumb'); ?> and a Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING on <h5><?php the_titlesmall('', '...', true, 55); ?></h5>. Removing these loads the page fine, but doesn't render the links as links, but instead as <?php the_permalink(); ?>.

If I'm just doing everything wrong here please let me know and I'll go ahead and close this question.

Thanks again for you time.

Improved question after author commented on his post. The question is now more clear.
Source Link

I'm looking to combine aHow can I query all the posts from either the custom post type ('videos'), or with a post category ('video') in a loop.?

I've managed to combinecreate a query that combines the posts from a custom post type together withand the normal posts using the code below, but am struggling with narrowing it down toachieving the same with a specificcustom post type and a post category.

<?php $args = array_merge( $wp_query->query, array( 'post_type' => array( 'post', 'videos', ) ) ); query_posts( $args ); ?>     
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>

Any help would be appreciated!

I'm looking to combine a custom post type ('videos'), with a post category ('video') in a loop.

I've managed to combine the custom post type together with normal posts using the code below, but am struggling with narrowing it down to a specific category.

<?php $args = array_merge( $wp_query->query, array( 'post_type' => array( 'post', 'videos', ) ) ); query_posts( $args ); ?>     
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>

Any help would be appreciated!

How can I query all the posts from either the custom post type ('videos') or with a post category ('video') in a loop?

I've managed to create a query that combines the posts from a custom post type and the normal posts using the code below, but am struggling with achieving the same with a custom post type and a post category.

<?php $args = array_merge( $wp_query->query, array( 'post_type' => array( 'post', 'videos', ) ) ); query_posts( $args ); ?>     
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>

Any help would be appreciated!

Source Link
kallekillen
  • 158
  • 3
  • 4
  • 15

Combining custom post type and post category

I'm looking to combine a custom post type ('videos'), with a post category ('video') in a loop.

I've managed to combine the custom post type together with normal posts using the code below, but am struggling with narrowing it down to a specific category.

<?php $args = array_merge( $wp_query->query, array( 'post_type' => array( 'post', 'videos', ) ) ); query_posts( $args ); ?>     
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>

Any help would be appreciated!