// Load WordPress environment
require( 'wp-load.php' );
// Query posts to include in the sitemap
$args = array(
'post_type' => 'post',
'posts_per_page' => -1,
);
$posts = new WP_Query( $args );
if ( $posts->have_posts() ) {
while ( $posts->have_posts() ) {
$posts->the_post();
$post_id = get_the_ID();
$post_url = get_permalink( $post_id );
// Get attached images
$images = get_attached_media( 'image', $post_id );
if ( ! empty( $images ) ) {
$sitemap .= '