Skip to content

Instantly share code, notes, and snippets.

@softiconic
Last active December 2, 2023 18:50
Show Gist options
  • Save softiconic/db77e81b63580bf51a6b7096ec36507b to your computer and use it in GitHub Desktop.
Save softiconic/db77e81b63580bf51a6b7096ec36507b to your computer and use it in GitHub Desktop.
Display posts using the shortcode [news id='1,2,3'].
<?php
// news
add_shortcode( 'news', 'news_shortcode' );
function news_shortcode( $atts ) {
extract(shortcode_atts(array(
'id' => null
), $atts, 'news'));
$post_ids = explode(",", strval($id));
ob_start();
$query = new WP_Query( array(
'post_type' => 'news',
//'posts_per_page'=>4,
'orderby' => 'post__in',
'post__in' => $post_ids
) );
if ( $query->have_posts() ) { ?>
<div class="owl-carousel slidersc">
<?php while ( $query->have_posts() ) : $query->the_post(); ?>
<div class="item">
<?php the_post_thumbnail('full'); ?>
</div>
<?php endwhile;
wp_reset_postdata();
?>
</div>
<?php $myvariable = ob_get_clean();
return $myvariable;
return $this->grid($args);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment