Last active
December 2, 2023 18:50
-
-
Save softiconic/db77e81b63580bf51a6b7096ec36507b to your computer and use it in GitHub Desktop.
Display posts using the shortcode [news id='1,2,3'].
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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