[wp-testers] WP_Query rewrites $request.

Mani Monajjemi mani.monajjemi at gmail.com
Tue Jan 10 08:53:19 GMT 2006


I figured out this problem 4 months ago in ver 1.5.2 but I was not sure that
It was a bug or It was my mistake, I wanted to submit a trac ticket but I
was not able to explain the problem well, You are right about the reason ,
but Some experts/developers may have the best answer.

On 1/9/06, Jamie Talbot <wphackers at jamietalbot.com> wrote:
>
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> Hi,
>
> Trying to get a multiple 'The Loop' template working, I came across
> something unexpected.  Following the instructions in the Codex[1], I
> created a new WP_Query and used it for the subsection of posts that I
> needed (a moblog category).
>
> $keitai_display = new WP_Query('category_name=keitai&showposts=2');
> while ($keitai_display->have_posts()) : $keitai_display->the_post();
> <!-- Do some stuff -->
> endwhile;
>
> After doing stuff for that one category, I called The Loop as usual:
>
> if (have_posts()) : while (have_posts()) : the_post();
> <!-- Do some more stuff -->
> endwhile;
> post_nav_link();
>
> The posts displayed as expected but the page numbering in post_nav_link
> was screwed up, saying only 2 pages, instead of 18.  Saving $request
> before calling new WP_Query and then replacing it afterwards fixed the
> problem.
>
> $saved = $request;
> $keitai_display = new WP_Query('category_name=keitai&showposts=2');
> while ($keitai_display->have_posts()) : $keitai_display->the_post();
> <!-- Do some stuff -->
> endwhile;
> $request = $saved;
> if (have_posts()) : while (have_posts()) : the_post();
> <!-- Do some more stuff -->
> endwhile;
> post_nav_link();
>
> $request is overwritten in WP_Query->get_posts() (Line 645 or
> thereabouts).  Because the $request is built for $wp_query first, any
> new WP_Query objects in a template will overwrite it.  Instead of
> changing $request for each new WP_Query, could the query string be
> assigned to a class member variable?  This way, each WP_Query would have
> it's own request string, which would remain consistent.
>
> I haven't submitted a ticket for this yet, because I don't know the
> extent to which $request is used throughout the rest of the code (or if
> other plugins rely on it being written this way).  Is it a bug?  Or just
> the expected behaviour and an omission from the documentation?
>
> Cheers,
>
> Jamie
>
> [1] http://codex.wordpress.org/The_Loop - Multiple Loops Example 3
>
> - --
> http://jamietalbot.com
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.2.5 (MingW32)
> Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org
>
> iD8DBQFDwpPTrovxfShShFARAtOvAJ4tIEVwPahY7+SReNroNkLzQRzpLgCePZpV
> OAeSVhEZd+xPNIsGjB45cEs=
> =qYVe
> -----END PGP SIGNATURE-----
> _______________________________________________
> wp-testers mailing list
> wp-testers at lists.automattic.com
> http://lists.automattic.com/mailman/listinfo/wp-testers
>



--
Mani Monajjemi
www.manionline.org
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://comox.textdrive.com/pipermail/wp-testers/attachments/20060110/a2766c3b/attachment.htm


More information about the wp-testers mailing list