query_posts() ALWAYS displays something?
No it doesn’t at least not for me, i’ve tried the code you posted inside my child theme and was unable to reproduce the issue described.
Firstly, i tried…
while ( have_posts() ) : the_post(); ?>
<!--- DO NOTHING ! -->
<?php endwhile ?>
..and got nothing, so i then tested..
<?php
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
query_posts("posts_per_page=1&paged=$paged");
global $more;
$more = 0;
while ( have_posts() ) : the_post(); ?>
<h1><?php the_title();?></h1>
<h3><?php the_content( __( '') ); ?></h3>
<?php endwhile ?>
..which produced..
<h1>Post title</h1>
<h3><p>post content</p></h3>
No stray paragraph of content.
If i had to guess at the problem, i’d say there’s a badly coded filter or shortcode at work. Easiest way to isolate the cause (as with any WP troubleshooting) would be to disable plugins and/or switch theme and narrow down which is causing the problem.
UPDATE:
Use a new WP_Query
object instead of query_posts
and that should clear up the problem.
function posts_shortcode( $atts ) {
extract( shortcode_atts( array(
), $atts ) );
global $more, $wp_query;
$args = array(
'posts_per_page' => 1,
'paged' => get_query_var('paged')
);
$q = new WP_Query;
$q->query( $args );
// Backup $wp_query
$backup = $wp_query;
// Fill $wp_query with the custom query
$wp_query = $q;
// Do the loop
while ( $q->have_posts() ) :
$q->the_post();
$more = 0;
?>
<h1><?php the_title();?></h1>
<h3><?php the_content( __( '') ); ?></h3>
<?php
endwhile;
// Output page navi
wp_pagenavi();
// Restore $wp_query
$wp_query = $backup;
// Restores wp_query global and also resets postdata(may not be needed, but won't hurt)
wp_reset_query();
}
add_shortcode('posts', 'posts_shortcode');