Wordpress Shortcode从MySql查询一些值

| 我有一个MySql表,在其中放置了一些值:id,机会名称,机会类别,佣金等。现在,我需要(自动)创建一个短代码来调用这些值,从而赢得一个数组,例如,如果我在具有
id=1
的数据库中写入
[opportunity id=\"1\"]
wordpress展示机会的横幅。 这是我的代码
function opportunity_banner_shortcode($atts) { 
    extract(shortcode_atts(array(\"id\" => \'\'), $atts));

  global $table_prefix, $wpdb, $user_level;
  $table_name = $table_prefix . \"opportunities\";

  $finds = $wpdb->get_results(\"SELECT * FROM {$table_name}\", ARRAY_A);
  if(sizeof($finds)){
    foreach($finds as $find) 
        return \"<a href=\'\" . $find[\"opp_link\"]. 
               \"\'><img src=\'\" . $find[\"opp_banner_preview\"].\"\'></a> \";
    } 
}
add_shortcode(\'opportunity\', \'opportunity_banner_shortcode\');
谢谢大家     
已邀请:
        也许查询应该是
$finds = $wpdb->get_results(\"SELECT * FROM {$table_name} WHERE id={$id}\",
   ARRAY_A);
    

要回复问题请先登录注册