Skip to content

Instantly share code, notes, and snippets.

@cccamuseme
Last active July 11, 2018 21:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cccamuseme/7883db83755e4eba7f1c84bf162fd2e9 to your computer and use it in GitHub Desktop.
Save cccamuseme/7883db83755e4eba7f1c84bf162fd2e9 to your computer and use it in GitHub Desktop.
Custom post type slider
<div class="bx-wrapper">
<ul class="bxslider">
<?php
$slider = new WP_Query(array( 'post_type' => 'homepage_slider' ) );
if( $slider->have_posts() ) :
while($slider->have_posts()) :
$slider->the_post();
$thumb = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), 'full' ); ?>
<li class="featured-image" style="background-image: url('<?php echo $thumb['0'];?>')">
<div class="slide-wrapper">
<div class="slide-inner">
<?php the_content() ?>
</div>
</div>
</li>
<?php
endwhile;
endif;
wp_reset_postdata();
?>
</ul><!-- /.bxslider -->
</div><!-- /.bx-wrapper -->
@WPDevHQ
Copy link

WPDevHQ commented Aug 31, 2016

I would discourage the use of both query_posts() and wp_rest_query() as they are considered bad practice. Use the new WP_Query() with wp_reset_postdata().

Here's what the ammended code would look like... Revised CPT Slider

@cccamuseme
Copy link
Author

Thanks, updated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment