通过短码替换值

时间:2011-08-30 作者:adolfozen

function add_listing( $atts)
 { extract( shortcode_atts( array (
\'sslug\' => \'\',
\'jslug\' => \'\'
  ), $atts ) );

global $wpdb;
$qstr = \'   
SELECT * 
FROM $wpdb->posts   
LEFT JOIN $wpdb->term_relationships ON($wpdb->posts.ID = $wpdb->term_relationships.object_id)    
LEFT JOIN $wpdb->term_taxonomy ON($wpdb->term_relationships.term_taxonomy_id = $wpdb->term_taxonomy.term_taxonomy_id)
LEFT JOIN $wpdb->terms ON($wpdb->term_taxonomy.term_id = $wpdb->terms.term_id)
WHERE $wpdb->posts.post_type = "states" 
AND $wpdb->posts.post_status = "publish"
AND $wpdb->term_taxonomy.taxonomy = "usstates"
AND $wpdb->term_taxonomy.taxonomy = "job-desc" 
AND $wpdb->terms.slug =  $sslug;   <-----
OR $wpdb->terms.slug =   $jslug;    <--------
ORDER BY $wpdb->posts.post_date DESC
\';
  add_shortcode("list", "add_listing");
我想替换值,例如:

这是我的示例短代码

[list sslug="alabama" jslug="electrician"]
我想将该值替换为上面的箭头

但无法使其发挥作用:(

请帮帮伙计们

1 个回复
SO网友:kaiser

如果将变量放入字符串中,则必须使用" 双引号。

因此:

// This:
$qstr = \'
SELECT *
...
ORDER BY $wpdb->posts.post_date DESC
\';

// becomes...
$qstr = "
SELECT *
...
ORDER BY $wpdb->posts.post_date DESC
";

结束

相关推荐

Shortcode empty attribute

有没有办法为短代码创建一个空属性?示例:function paragraph_shortcode( $atts, $content = null ) { return \'<p class=\"super-p\">\' . do_shortcode($content) . \'</p>\'; } add_shortcode(\'paragraph\', \'paragraph_shortcode\'); 用户类型某物它显