Make WordPress Core

Opened 11 years ago

Closed 11 years ago

Last modified 11 years ago

#4162 closed defect (bug) (invalid)

query_posts('p=<id>') = always a full post

Reported by: devil1591 Owned by:
Milestone: Priority: high
Severity: blocker Version: 2.2
Component: General Keywords:
Focuses: Cc:


On svn, if you do a


you will have the full post instead of having the first part of the post with a <!--more--> tag.

Change History (5)

#1 @johnbillion
11 years ago

  • Milestone 2.2 deleted
  • Resolution set to invalid
  • Status changed from new to closed

The code


on its own displays nothing, you need to use it in conjunction with other code which can determine whether the whole post or just the excerpt is displayed. See the query_posts page on Codex for more information.

#2 @devil1591
11 years ago

  • Milestone set to 2.2
  • Resolution invalid deleted
  • Status changed from closed to reopened

Thanks, I know that query_posts alone doesn't show anything...

That code shows the full post

while (have_posts()) : the_post();
the_content('Read the full post &raquo;');

That one only shows the first part, as it should be, isn't it a bug ?

$q = new WP_query('p=1');
while ( $q->have_posts() ) : $q->the_post();
the_content('Read the full post &raquo;');

In fact, the problem seems to be in get_the_content, because if you set the global $more to 0 in the first case, you'll display only the first part of the post BUT if you set $more to 1 in the second case, you'll also display the first part.

#3 @Otto42
11 years ago

  • Resolution set to invalid
  • Status changed from reopened to closed

If you do a query_posts('p=1'), you're supposed to get the whole post back. Doing this will cause $is_single to be set to true, since you're requesting a single post. And setup_postdata() will then force $more=1 when is_single() returns true.

The reason that your "new WP_Query()" functionality doesn't do that is because you created your own query instead of using the global one, and thus did not set the normal default query's $is_single but set a local one instead. And so setup_postdata(), which is looking at the default query only, does not see the is_single() and thus does not force $more=1.

In other words, I believe this is expected behavior. Creating a new query and using the default query are actually two different things, not just different ways of doing the same thing.

#4 @foolswisdom
11 years ago

  • Milestone 2.2 deleted

#5 @devil1591
11 years ago

ok, sorry, it's clear to me now :)

Btw, the codex needs some explanation on that behavior.

Note: See TracTickets for help on using tickets.