Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
139 views
in Technique[技术] by (71.8m points)

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' );
question from:https://stackoverflow.com/questions/65944089/wordpress-shortcode-breaks-when-using-multiple-on-a-single-page

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...