0

I'm making a really simple cycle where I need to print a Custom Post Type with my style (that isn't defined yet in the script below but is where I print the_thime) and it's working. The problem is that in the bottom of the page, just before the footer, "something" is printing the title of my posts.

That's the function:

function shortcode_eventi() {
     query_posts(array( 
                'post_type' => 'eventi'
    ) );  
?>
<?php if (have_posts()) : ?>
<?php while (have_posts()) : the_post(); ?>
    <small><?php the_time('F jS, Y') ?></small>
<?php endwhile; ?>
<?php else : ?>
<h2 class="center">Not Found</h2>
<p class="center"><?php _e("Sorry, but you are looking for something that isn't here."); ?></p>
<?php endif; ?>
<?php   
}   

No ideas about the problem.

2

Instead of query_posts(), use WP_Query():

function shortcode_eventi() {
     $loop = new WP_Query(array( 
         'post_type' => 'eventi'
     ));  
?>
    <?php if ($loop->have_posts()) : ?>
        <?php while ($loop->have_posts()) : $loop->the_post(); ?>
            <small><?php the_time('F jS, Y') ?></small>
        <?php endwhile; ?>
    <?php else : ?>
        <h2 class="center">Not Found</h2>
        <p class="center"><?php _e("Sorry, but you are looking for something that isn't here."); ?></p>
    <?php endif; ?>
<?php   
}   

Read about WP_Query on the WordPress Codex

Also read this good piece, why not to use query_posts()

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.