VARIS VONGUEA-AREE

PHP 🐍 Python 🔥 Golang 🇹🇭 Bangkok Thailand

High level experience in web design and development knowledge, producing quality work.

For more info
  • Home
  • About
  • Project
  • Blog
  • Varisz
  • Wordpress CMS
  • WordPress Shortcode

WordPress Shortcode

บ่อยครั้งที่เราต้องเรียกใช้งานฟังก์ชั่นที่เรา Custom มาเอง


add_shortcode('testimonials_loop', 'testimonials_query');

function testimonials_query(){

    $args = array(
      'post_type'         => 'testimonials',
      'orderby'          => 'order',
      'order'            => 'ASC'
    );

$query = new WP_Query($args);

 if($query->have_posts()){
         while($query->have_posts()) : $query->the_post();

         $html = get_the_title().'<br>';
         $html .= get_the_ID();endwhile;

 } 
 return $html;

}//End function

ในการเรียกใช้งาน shortcode นี้ แบบ PHP เรียกได้จาก

<?php echo do_shortcode('[testimonial_rotator id=7296]'); ?>

© 2021 All rights reserved by varisz