我创建了一个带有属性的小快捷码函数,以检查属性是否得到正确处理。就是这样,现在我想在SELECT语句中使用该属性。但数据库没有提供任何值。WHERE条件中没有变量的SQL语句正常。
为了测试短代码,我在Wordpress文本页中添加了这三行代码,但它们都不起作用:
[simplelist text=Beatles]
[simplelist text=\'Beatles\']
[simplelist text="Beatles"]
这是我的函数代码。php: <?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\' );
?>
当我删除WHERE条件时,我会得到完整的表结果。我需要一些在WHERE条件下使用属性值的帮助。