php - Wordpress shortcode breaks when using multiple on a single page

I have created a shortcode of a custom post type. I also have a custom taxonomy attached to it. when I am using it on a page multiple times it is breaking the layout and not working. On the page, I have a tab with multiple options. I want to show different category posts in a different tab. but all are showing in one tab and not working properly. I have an almost similar custom post shortcode that is working properly. what I am doing wrong. thanks
function sonderposten_function( $attr ) {
ob_start();
extract( shortcode_atts( array(
'type' => 'sonderposten',
'order' => 'DESC',
'orderby' => 'ID',
'posts' => -1,
'category' => '',
), $attr ) );
$args = array(
'post_type' => $type,
'post_status' => 'publish',
'posts_per_page' => $posts,
'paged' => get_query_var( 'paged' ),
'tax_query' => array(
array(
'taxonomy' => 'reparaturs_category',
'field' => 'slug',
'terms' => array( $category )
)
)
);
$the_query = new WP_Query( $args );
?>
<div class="sonderposten_holder">
<?php
if ( $the_query->have_posts() ):
while ( $the_query->have_posts() ): $the_query->the_post();
?>
<?php
endwhile;
wp_reset_postdata();
?>
</div>
<!-- sonderposten_holder -->
<?php else : ?>
<p>Sorry, nothing to show </p>
<?php
endif;
return ob_get_clean();
}
add_shortcode( 'sonder_postens', 'sonderposten_function' );
Share solution ↓
Additional Information:
Link To Answer People are also looking for solutions of the problem: undefined array key php
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.