"ShortCode As per Category"
Bootstrap 4.1.1 Snippet by iammohitverma

<link href="//maxcdn.bootstrapcdn.com/bootstrap/4.1.1/css/bootstrap.min.css" rel="stylesheet" id="bootstrap-css"> <script src="//maxcdn.bootstrapcdn.com/bootstrap/4.1.1/js/bootstrap.min.js"></script> <script src="//cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script> <!------ Include the above in your HEAD tag ----------> <div class="container"> <div class="row"> <h2>Create your snippet's HTML, CSS and Javascript in the editor tabs</h2> </div> </div>
add_shortcode("products-list" , function($atts = [], $content = null, $tag = ''){ if(is_admin()){ return; } ob_start(); // normalize attribute keys, lowercase $atts = array_change_key_case((array)$atts, CASE_LOWER); // override default attributes with user attributes $prod_atts = shortcode_atts([ 'category' => false, ], $atts, $tag); $args = array( 'post_type' => 'products', 'posts_per_page' => -1, 'post_status' => 'publish', ); if($prod_atts["category"] && $prod_atts["category"] != ""){ $term = explode(",",$prod_atts["category"]); $tax_query = array( array( 'taxonomy' => 'products_cat', 'field' => 'slug', 'terms' => $term, ), ); $args["tax_query"] = $tax_query; } ?> <ul class="product-box-wrap"> <?php query_posts($args); if(have_posts()): while(have_posts()): the_post(); ?> <li> <div class="product-list-detail"> <div class="top-text"> <h2> <?php echo get_the_title();?> </h2> <h3>Medicated for-</h3> <?php echo get_the_content();?> </div> <div class="bottom-text"> <a class="btn-more-detail" href="<?php echo get_the_permalink();?>"> More Details </a> </div> </div> </li> <?php endwhile; endif; ?> </ul> <?php wp_reset_query(); return ob_get_clean(); });

Related: See More


Questions / Comments: