admin管理员组文章数量:1313347
I'm working on a plugin to use gettext in posts and pages content.
I'm trying to get all published posts and pages in order scan them for translatable strings, but I cannot figure out how to do it.
This is what I'm trying:
$pages = $wpdb->query('SELECT * FROM wp_posts WHERE post_status = "publish"');
foreach ( $pages as $post ) {
print_r($post);
}
I'm working on a plugin to use gettext in posts and pages content.
I'm trying to get all published posts and pages in order scan them for translatable strings, but I cannot figure out how to do it.
This is what I'm trying:
$pages = $wpdb->query('SELECT * FROM wp_posts WHERE post_status = "publish"');
foreach ( $pages as $post ) {
print_r($post);
}
Share
Improve this question
asked Mar 10, 2014 at 13:39
Lisandro VaccaroLisandro Vaccaro
9954 gold badges12 silver badges28 bronze badges
2 Answers
Reset to default 2Don't use pure SQL if you don't have to. WordPress provides a useful and relatively solid class for retrieving post data. Use it.
$args = array(
'post_type' => array('post','page'),
'post_status' => 'publish',
'posts_per_page' => -1,
'ignore_sticky_posts' => true,
);
$qry = new WP_Query($args);
// Show post titles
foreach ($qry->posts as $p) {
echo $p->post_title;
}
Reference:
http://codex.wordpress/Class_Reference/WP_Query
Try this,
global $wpdb;
$posts = $wpdb->get_results( $wpdb->prepare("SELECT * FROM $wpdb->posts WHERE post_status = 'publish'"));
foreach ( $posts as $post ) {
print_r($post);
}
本文标签: wpdbGet published posts and pages
版权声明:本文标题:wpdb - Get published posts and pages? 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741904932a2404086.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论