我有以下WP功能和我编写的短代码
function selected_inventory_products( $atts ) {
extract( shortcode_atts( array(
'brand' => '',
'product' => '',
), $atts ) );
global $wpdb;
$inventory_products = $wpdb->get_results("SELECT * FROM wp_inventory, wp_inventory_images WHERE wp_inventory.inventory_id = wp_inventory_images.inventory_id and sort_order = 0 and inventory_manufacturer = '".$brand."'");
foreach($inventory_products as $i_products){
$return_string = '<div style="background: #F4F4F4; width: 100%;">';
$return_string .= '<a href="http://www.devicemondo.com/products/item/'.$i_products->inventory_slug.'/">'.$i_products->inventory_name.'</a>';
$return_string .= '</div>';
}
return $return_string;
}
add_shortcode( 'post_sidebar_products', 'selected_inventory_products' );
问题是,当我在WP页面中使用短代码[post_sidebar_products]时,即使有超过15的结果,我也只得到1个结果?知道我犯了哪个错误吗?
感谢您的帮助
答案 0 :(得分:1)
啊!刚看到它。你每次在循环中重新定义$ return_string!由于第一行,在等号前没有点。所以替换这个:
$return_string = '<div style="background: #F4F4F4; width: 100%;">';
用这个:
$return_string .= '<div style="background: #F4F4F4; width: 100%;">';