HOME / BLOG / BLOG-POST

How to create a custom short code for getting data from database table in wordpress?

 

// wordpress custom shortcode by wpdevkit.in
function sdSlidesShortCode($attr){
    
    $array = shortCodeAtts(array(
        'id' => '',
    ), $attr);

    global $wpdb;
    $table_name  = $wpdb->prefix . "";
    $id = $array['id'];
    $results = $wpdb->get_results("SELECT * FROM $table_name WEHERE ID = '$id'");
    foreach($results as $result){
        $slidesContent = $result->slidesContent;
    }
    
    $output = $slidesContent;
    return $output;
}
add_shortcode('SlideShortCode','sdSlidesShortCode');

 


about authors

Sandip Das

Web Developer

Once a legend said “Any fool can write code that a computer can understand. Good programmers write code that humans can understand.” – Martin Fowler.



POST COMMENTS

Leave a Reply

Your email address will not be published. Required fields are marked *