admin管理员组文章数量:1331443
$table = $wpdb->prefix . 'posts';
foreach ( $wpdb->get_col( "DESC " . $table, 0 ) as $column ){//get all columns from wp_posts
echo "<div><p>".
$counter."- ".$column." => ".
"<input class='input_triplify_posts' value='correspondence' id='correspondence".$counter."' mk='".$column."' />".
"</p></div>";
$counter++;
}
Guys, with this code I can get all columns data from the table wp_posts in my database. I just want to get the data from a column named "guid" from the same table. What I have to modify in the code above? Thanks.
$table = $wpdb->prefix . 'posts';
foreach ( $wpdb->get_col( "DESC " . $table, 0 ) as $column ){//get all columns from wp_posts
echo "<div><p>".
$counter."- ".$column." => ".
"<input class='input_triplify_posts' value='correspondence' id='correspondence".$counter."' mk='".$column."' />".
"</p></div>";
$counter++;
}
Guys, with this code I can get all columns data from the table wp_posts in my database. I just want to get the data from a column named "guid" from the same table. What I have to modify in the code above? Thanks.
Share Improve this question asked Jan 21, 2015 at 20:14 EduardoEduardo 211 silver badge3 bronze badges1 Answer
Reset to default 2Try this. Hopefully I've interpreted your output correctly.
I'd recommend a good read of the $wpdb
codex, particularly in relation to the get_col()
method - http://codex.wordpress/Class_Reference/wpdb#SELECT_a_Column
global $wpdb; // You won't need this unless this code is within a function
$query = $wpdb->prepare(
'SELECT %1$s.guid FROM %1$s',
$wpdb->posts
);
$results = $wpdb->get_col($query);
$counter = 1; // Ignore this if you already set counter somewhere else, or change it as required
if(!empty($results)) : foreach($results as $result) :
echo '<div><p>';
printf(
'%1$s- %2$s =>',
$counter,
$result
);
printf(
'<input class="input_triplify_posts" value="correspondence" id="correspondence%1$s mk="%2$s" />',
$counter,
$result
);
echo '</p></div>';
$counter++;
endforeach;
endif;
本文标签: pluginsDoubt using wpbdgtgetcol for a single column
版权声明:本文标题:plugins - Doubt using $wpbd->get_col for a single column 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742262780a2442827.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论