WordPress.org

Make WordPress Core

Opened 7 years ago

Closed 7 years ago

Last modified 7 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:

Description

On svn, if you do a

query_posts('p=1');

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

Change History (5)

comment:1 johnbillion7 years ago

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

The code

query_posts('p=1');

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.

comment:2 devil15917 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

query_posts('p=1');
while (have_posts()) : the_post();
the_content('Read the full post &raquo;');
endwhile;

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;');
endwhile;

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.

comment:3 Otto427 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.

comment:4 foolswisdom7 years ago

  • Milestone 2.2 deleted

comment:5 devil15917 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.