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);
}
Don’t use pure SQL if you don’t have to. WordPress provides a useful and relatively solid class for retrieving post data. Use it.
Reference:
http://codex.wordpress.org/Class_Reference/WP_Query
Try this,