OK, I’m using posts_query() to display posts.
The problem is, at least in my case, posts_query() always outputs something.
For example:
<?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(); ?>
<!--- DO NOTHING ! -->
<?php endwhile ?>
Displays raw first part of a post (and without $more = 0 the whole post).
Why is it happening?
I want to style the output on my own, but I’m not able to, because for example:
while ( have_posts() ) : the_post(); ?>
<h1><?php the_title();?></h1>
<h3><?php the_content( __( '') ); ?></h3>
<?php endwhile ?>
Gives:
<h1>MyTitle</h1>
<h3>something something something something something</h3>
<p>something something something something something</p> <!-- (wherethis line comes from? ;/) ?>
PS.
In addition I’m almost sure pagination doesn’t work as well, and I believe it should this way? I have around 15 posts to display, I’ve chosen 1, why there’s no navi? 🙁
The exact code:
function posts_shortcode( $atts ) {
extract( shortcode_atts( array(
), $atts ) );
query_posts("posts_per_page=1");
global $more;
$more = 0;
while ( have_posts() ) : the_post(); ?>
<h1><?php the_title();?></h1>
<h3><?php the_content( __( '') ); ?></h3>
<?php endwhile;
}
add_shortcode('posts', 'posts_shortcode');
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…
..and got nothing, so i then tested..
..which produced..
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 ofquery_posts
and that should clear up the problem.Does same thing happen if you use
the_post()
without while loop? Does same thing happen if you don’t use customquery_posts()
call?This seem awfully like poorly coded filter somewhere in chain, but it’s hard to guess location from this.
You could try this code to dump names of filters as they run and try to pinpoint which might cause it: