I have a custom post type leistungencpt
with categories. Now I`m planning to show all posts from this CPT but from an certain category of this CPT with an shortcode.
My code
function my_custom_sliderlesoftware( $atts, $content = null ) {
/* Turn on buffering */
ob_start();
$anzahl = shortcode_atts(array(
'anzahl' => '#',
), $atts);
$args = array(
'post_type' => 'leistungencpt',
'product_cat' => 'le-software-entwicklung',
'posts_per_page' => $anzahl['anzahl'],
'facetwp' => true ,
);
$query = new WP_Query( $args );
?>
<div class="post_box">
<?php if ( $query->have_posts() ) : while ( $query-> have_posts() ) : $query-> the_post(); ?>
<div class="vc_col-sm-4 post_boxinner">
<div class="post_img">
<a href="<?php the_permalink() ?>" title="<?php the_title(); ?>"><?php echo get_the_post_thumbnail( get_the_ID(), 'startgrid' ); ?></a>
</div>
<h3 class="post_headline"><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></h3>
<p class="post_excerpt"><?php
echo wp_trim_words( get_the_excerpt(), 22, ' […]' );
?></p>
<div class="vc_btn3-container vc_btn3-left vc_do_btn">
<a class="vc_general vc_btn3 vc_btn3-size- vc_btn3-shape- vc_btn3-style-btn btn-rahmen vc_btn3-color-green" href="<?php the_permalink() ?>" title="Weiterlesen">Weiterlesen</a>
</div>
</div>
<?php
endwhile;
wp_reset_postdata(); // this should be inside if - there is no need to rested postdata if the_post hasn’t been called.
endif;
?>
</div>
<?php
/* Get the buffered content into a var */
$sc = ob_get_contents();
/* Clean buffer */
ob_end_clean();
/* Return the content as usual */
return $sc;
}
add_filter('widget_text','do_shortcode');
How is the right loop for all posts in certain category from the CPT leistungencpt?
I have tried many ways, but nothing is happening, no posts will show up in the frontend.