我一整天都在寻找一种方法来为短代码添加属性。我要添加的属性是自定义的ID
wp_table
.
我试图获得的输出是,例如:
[launch_tincan id="1"]
当收到我的自定义中第1行的信息时
wp_表格
,我可以用这些信息填充vars。
我有一个函数,如果我硬编码
get_results
从一行中
id=#
,我的简码正确填充,但是,我希望简码包含id。
我见过很多使用wp_posts之类的例子,但没有一个对我有用。
我注意到的另一件事是,似乎没有人从函数中的函数生成简码。这可能吗?
下面是我的代码示例:
<?php
// WP Shortcode to display info from content in my table
function my_shortcode_functions(){
global $wpdb;
$getinfo = $wpdb->get_results($wpdb->prepare("SELECT id,col1,col2,col3,col4 from my_table",$id));
foreach ($getinfo as $s ){
$col1=$s->col1;
$col2=$s->col2;
$col3=$s->col3;
$col4=$s->col4;
}
if ( is_user_logged_in() ) {
?>
<div>
<form method="post">
<input type="submit" onClick="window.open(document.getElementById('results').innerHTML);" value="Open" class='button'/>
</form>
</div>
<div style="visibility:hidden; height:0px; width:0px;" id="results">
<?php
echo $col1 . $col2 . $col3 . $col4;
?>
</div>
<?php
} else {
echo "You must be logged in to use this";
}
}
add_shortcode('my_shortcode', 'my_shortcode_functions');
?>
有没有可能
add_shortcode
函数嵌套在
my_shortcode_functions
?
我的
get_shortcode_id
函数看起来应该工作吗?
我期待着任何帮助来纠正我的代码,或者让我知道我是否走错了方向。