WordPress shortcode attributes for database SELECT?

I have created a small shortcode function with attributes to review if
attributes are handled properly. That’s the case and now I would like
to use the attribute in a SELECT statement. But the database does not provide any values. The SQL statement without variable in the WHERE condition is okay.

To test shortcodes, I’ve added this three lines into my WordPress text page, but nor of them is working:

[simplelist text=Beatles]
[simplelist text=’Beatles’]
[simplelist text=”Beatles”]

And here is my code from functions.php:


function get_list( $atts )
$atts = shortcode_atts( array(
‘text’ => ”,
), $atts);

global $wpdb;

$simplelist = $wpdb->get_results(“SELECT `Row1`, `Row2`
FROM `table`
WHERE `Row1` = ” . $atts[text] . ”
ORDER BY `Row1` ASC”);

$Result = …. some stuff here …
return $Result;
add_shortcode(‘simplelist’, ‘get_list’ );

When I remove the WHERE condition, I get complete table results. I need some help in using attribute values in WHERE condition.

Read more here:: WordPress shortcode attributes for database SELECT?

Leave a Reply

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