Advertisement
firoze

category support in shortcode

Jul 14th, 2015
226
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.12 KB | None | 0 0
  1. // category support in shortcode if want to support category by shortcode then create new category for every post suppose if you want to use 4 post then make seperately 4 new category
  2.  
  3. <div class="container">
  4. <div class="row">
  5. <div class="col-md-6">
  6. <div class="bootstrap_accordion">
  7. <?php
  8. $loop = new WP_Query(array('post_type' => 'accordion_bar', 'posts_per_page' =>-1));
  9. $count =0;
  10. ?>
  11. <?php if ( $loop ) :
  12.  
  13. while ( $loop->have_posts() ) : $loop->the_post(); ?>
  14.  
  15. <?php
  16. $terms = get_the_terms( $post->ID, 'accordion_category' ); // name of the taxonomy
  17.  
  18. if ( $terms && ! is_wp_error( $terms ) ) :
  19. $links = array();
  20.  
  21. foreach ( $terms as $term )
  22. {
  23. $links[] = $term->name;
  24. }
  25. $links = str_replace(' ', '-', $links);
  26. $tax = join( " ", $links );
  27. else :
  28. $tax = '';
  29. endif;
  30. ?>
  31. <?php echo do_shortcode('[items category="'.strtolower($tax).'"]');?>
  32. <?php endwhile;?>
  33. <?php endif; ?>
  34. </div>
  35. </div>
  36. </div>
  37. </div>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement