WordPress.org

Ready to get started?Download WordPress

Forums

XML not generating (2 posts)

  1. awx2d
    Member
    Posted 6 years ago #

    Hi
    I'm generating a XML file using the following code but the xml only displays when I'm logged in, once I log out of the admin the code no longer works, any ideas? I have a funny feeling it is to do with the id not being passed, is there a way to manually pass this or to use another variable to generate the xml?

    <?php
    require('./wp-config.php');
    header('Content-type: text/xml; charset=utf-8');
    
    function ssp_fetch_images($postid) {
        global $wpdb;
        return $wpdb->get_results("SELECT guid, post_title, post_content, post_excerpt FROM $wpdb->posts WHERE post_parent = $postid AND post_mime_type = 'image/jpeg'");
    }
    
    if(isset($_GET['cat'])) {
    $cat = $_GET['cat'];
    $query = "cat=$cat&showposts=1000";
    } else {
    $query = "showposts=1000";
    } ?>
    <gallery>
        <?php $gallery = new WP_Query($query);
        while ($gallery->have_posts()) : $gallery->the_post(); ?>
        <album id="<?php echo htmlspecialchars($post->post_title); ?>" title="<?php echo htmlspecialchars($post->post_title); ?>" description="<?php echo htmlspecialchars($post->post_excerpt); ?>" tn="<?php $key=($post->post_title); echo get_post_meta($post->ID, $key, true); ?>">
            <?php $images = ssp_fetch_images($post->ID);
            foreach($images as $image) { ?>
            <img src="<?php echo $image->guid; ?>" tn="<?php echo $image->guid; ?>" title="<?php echo htmlspecialchars($image->post_title); ?>" caption="<?php echo htmlspecialchars($image->post_title); ?>" />
            <?php } ?>
        </album>
        <?php endwhile; ?>
    </gallery>
  2. scribblerguy
    Member
    Posted 6 years ago #

    Have you tried requiring wp-blog-header.php instead of wp-config.php?

    With wp-blog-header.php, you can use the normal WP template tags.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.