WordPress issue with shortcodes

Asking for some help with setting the shortcode.
I’m trying to figure out how to make my own plugin and add shortcode for fast use. So might be something wrong here.

What i’ve got so far. I have working database table, which i can edit from the admin page from the plugin.

Now i want to refresh the data on the public side of the web-site.
All the code below is located in the benefits.php, which is in the plugin folder.
According to the Shortcode API, I’ve added a shortcut handler:

function get_benefits($attr) {
    $benefits = $wpdb->get_results(
        "
        SELECT * FROM wp_benefits;  
        "
    );

    $html = "<table class='benefits'>";
    $html .= "<tbody>";
    $html .= "<tr>";

    foreach ($benefits as $benefit) {
        $html .= "<th>".$benefit->Title."</th>";
    }

    $html .= "</tr>";
    $html .= "<tr>";

    foreach ($benefits as $benefit) {
        $html .= "<td>".$benefit->Content."</td>";
    }

    $html .= "</tr>";
    $html .= "</tbody>";
    $html .= "</table>";

    return $html;
}

And i’ve added a shortcode with this code:

add_shortcode( 'benefits', 'get_benefits'); 

All my recent tries turn into the zero content on this page. I mean the div class=”entry-content” is empty. But even with not working shortcode, i have to see an image there. I’m a little lost.

Would appreciate any help here.


Source: shortcode

Leave a Reply