WordPress.org

Make WordPress Core

Opened 7 years ago

Closed 7 years ago

Last modified 7 years ago

#5121 closed defect (bug) (fixed)

statistics reported back from wordpress 2.3 bugged

Reported by: ihad Owned by:
Milestone: 2.3.1 Priority: high
Severity: normal Version: 2.3
Component: General Keywords: has-patch
Focuses: Cc:

Description

After upgrading to wordpress 2.3, none of my statistic plugins (wp-stats 1.1.1 and SlimStat 1.605) work properly anymore.

It looks like all hits to posts are returned as hits for one post:
Spider-Man 3 (2007) 112
http://www.ihad.de/2007/05/06/spider-man-3-2007/
e.g.
a hit is listed as "Spider Man 3" but the link points to
http://www.ihad.de/2005/09/16/pitch-black-2000/
a totally different article.

I moved the post back to "draft" status and sure enough wp-stats (and SlimStats) started reporting all hits to any post as hits for post
My first 80386 PC 4
http://www.ihad.de/2007/04/10/my-first-80386-pc/

Since this happens with any statistic plugin I am a bit at a loss what could be the cause. Possibly the wp 2.3 DB changes? This happens no matter what theme I have active (even the wp 2.3 default theme).

I had a friend search for "Rome canceled" in goggle and click on the link that leads to my post:
http://www.ihad.de/2007/02/24/rome-season-3-cancelled/

afterwards the stats increased by one for the Spider-Man post...

Something is messed up and everything so far indicates it has to do with wp2.3

Attachments (1)

save_fist_wp_query_to_wp_the_query.patch (449 bytes) - added by 082net 7 years ago.

Download all attachments as: .zip

Change History (16)

comment:1 ihad7 years ago

  • Version set to 2.3

comment:2 ihad7 years ago

if any dev needs access to my stats for more info, let me know and I add your email.

comment:3 DD327 years ago

  • Milestone 2.5 deleted
  • Resolution set to invalid
  • Status changed from new to closed
  • Version 2.3 deleted

With the changes introduced, its likely that many plugins will need to be changed.
Check for updates for your plugins and see if they're compatible with WP 2.3.

Given theres no information here that shows WP has a bug, i'm going to close this as invalid, re-open it if you find (or the plugin author finds) something specifically wrong with WP (This seriously sounds like a plugin bug introduced by a DB change)

comment:4 ihad7 years ago

more info from 082net (SlimStats)

---quote--->
082net c-kr | October 2nd, 2007, 6:09 pm

ihad
I found that it's not related to K2 but WP_Query.

$wp_query was overridden by plugins, themes, and widgets using 'new WP_Query()' or 'query_posts()' and 'wp_reset_query()' seems does not works. ( I don't know why 'new WP_Query()' overrides $wp_query :-( Is it a bug or general? )

So, I decided to query the request again even if it's already queried by wordpress.

I'll update this plugin soon with another bug patches.

Thanks!
http://082net.com/2007/818/wp-slimstat-ex-v1_6/

<---end-quote---

I guess wordpress.com stats plugin needs an update too then?

-> http://wordpress.org/support/topic/136624?replies=3#post-625352

comment:5 ihad7 years ago

  • Resolution invalid deleted
  • Status changed from closed to reopened
  • Version set to 2.3

This is wordpress related after all, so I am reopening this ticket.

---quote--->
It was not a K2 bug.

It's the matter of when $wp_the_query->get_queried_object() is firstly called.

As I mentioned above, $wp_the_query->post is overrode by $post.

wp-settings.php
$wp_the_query =& new WP_Query();
$wp_query =& $wp_the_query;

wp-includes/class.php WP::register_globals()
$GLOBALSposts? = & $wp_query->posts;
$GLOBALSpost? = & $wp_query->post;

If a page haven't called $wp_the_query->get_queried_object() before a 'custom loop' (or something overriding $post or $posts), get_queried_object_id() would retun last post id of the 'custom loop'.

$wp_the_query->get_queried_object() would not stable until it is firstly called before any plugin or theme.

It seems stable 'cause it returns pre-set value if available.

function get_queried_object() {

if (isset($this->queried_object)) {

return $this->queried_object;

}

Because almost wordpress theme use 'wp_title()' for <title> </title> and wp_title call 'wp_query->get_queried_object()', there seems no problem.

For current K2 does not use wp_title() but the_title() which does not call 'get_queried_object', this issue seems related to K2.

Here's my suggestion to wordpress and I think it will help make $wp_the_query stable.

wp-includes/classes.php 'WP::query_posts()'

function query_posts() {

global $wp_the_query;
$this->build_query_string();
$wp_the_query->query($this->query_vars);
$wp_the_query->get_queried_object(); add this line

}

And temporary patch for K2 is replacing the_title() with wp_title() on header.php but it will not solve the whole problem.

<---- endquote from 082net (Thanks man, it worked for me for now).

comment:6 Nazgul7 years ago

  • Milestone set to 2.4

comment:7 foolswisdom7 years ago

  • Milestone changed from 2.4 to 2.5

comment:8 follow-up: andy7 years ago

  • Milestone changed from 2.5 to 2.3.1
  • Priority changed from normal to high

$wp_the_query must be fixed in the next bugfix release. Please do not push this back.

Proposed solution: at the end of wp(), do

global $wp_the_query, $wp_query;
if ( !isset( $wp_the_query ) )
  $wp_the_query = $wp_query;

without reference ampersand.

comment:9 in reply to: ↑ 8 Nazgul7 years ago

  • Keywords needs-patch added
  • Milestone changed from 2.3.1 to 2.4

Replying to andy:

$wp_the_query must be fixed in the next bugfix release. Please do not push this back.

Andy, tickets without a patch tend to get pushed back.
If you (or somebody else) is interested in seeing an issue fixed, attach a patch and tag it as has-patch. That way the core developers will notice it and usually include it much sooner.

Also, all fixes go into the current development branch first and are then sometimes backported to a maintenance release. Therefore I'm setting the milestone as 2.4 for now.

comment:10 foolswisdom7 years ago

  • Milestone changed from 2.4 to 2.3.1

Andy, is Andy Skelton, setting milestone to 2.3.1 . Don't know why he didn't attach the patch.

comment:11 082net7 years ago

  • Keywords has-patch added; needs-patch removed

Attached Andy's patch. (wp-includes/functions.php)

comment:12 andy7 years ago

Sorry about the missing patch, Nazgul. I was in a rush.

Thanks for making the patch, 082net. Does it work as intended? :-)

comment:13 082net7 years ago

It works very well and by the root :-)

comment:14 ryan7 years ago

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

(In [6232]) Make sure initial query is saved when calling wp(). Props andy. fixes #5121 for 2.3

comment:15 ryan7 years ago

trunk fixed with [6233]

Note: See TracTickets for help on using tickets.