Shortcode Condition
-
i want to use a condition with shortcode.
how can i use if else condition from shortcode. ?
Here is my code :
[ Moderator note: code fixed. Please wrap code in the backtick character or use the code button. ]
/*-----Query post in shortcode for testimonial content----*/ function testimonial_content_shortcode($atts){ extract( shortcode_atts( array( 'category' => '', 'count' => '', 'type' => 'post', ), $atts ) ); $q = new WP_Query( array('posts_per_page' => $count, 'post_type' => 'testimonial-items', 'order', 'ASC' ) ); $list = '<div class="col-md-6 wow fadeIn belal_all_testimonial" data-wow-duration="0.6s" data-wow-delay="0.3s">'; while($q->have_posts()) : $q->the_post(); $idd = get_the_ID(); $client_name = get_post_meta($idd, 'client_name', true); $company_name = get_post_meta($idd, 'company_name', true); $list .= ' <div id="testimonial-'.$idd.'" class="testimonail-detail"> <p> '.get_the_content().' </p> <div class="testimonial-info"> <span class="company"> Client Name: </span> <span class="name"> '.$client_name.' </span> <span class="company"> Company Name: </span> <span class="name"> '.$company_name.' </span> </div> </div> '; endwhile; $list.= '</div>'; wp_reset_query(); return $list; } add_shortcode('tcontent', 'testimonial_content_shortcode');
LOOK MY CODE . i want when i will put my client name then it will be show in my page Client Name: Belal . But when i will not select any name that’s why it will not show on My client name:
NB: i use option tree
Thanks for your reading in my Thread
Viewing 6 replies - 1 through 6 (of 6 total)
Viewing 6 replies - 1 through 6 (of 6 total)
- The topic ‘Shortcode Condition’ is closed to new replies.