Make WordPress Core

Opened 15 years ago

Closed 15 years ago

Last modified 15 years ago

#12446 closed defect (bug) (invalid)

"get_comments" transforms post id

Reported by: jmabe's profile jmabe Owned by:
Milestone: Priority: normal
Severity: normal Version:
Component: General Keywords:
Focuses: Cc:

Description

$post_id is being set to

$post_id = absint($post_id)

which would make a negative post id pull comments for the positive post id. This is problematic if by chance the post_id is set to -1, and you happen to have that first hello world post in there, it will always pull that first hello world comment.

Patch attached.

Attachments (1)

absint-on-postid.patch (332 bytes) - added by jmabe 15 years ago.

Download all attachments as: .zip

Change History (8)

#1 follow-up: @Denis-de-Bernardy
15 years ago

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

the database stores IDs as bigint(20) unsigned.

#2 in reply to: ↑ 1 @jmabe
15 years ago

Replying to Denis-de-Bernardy:

the database stores IDs as bigint(20) unsigned.

but what if your plugin is emulating a post object, and is passing a negative number for the ID :)

#3 @Denis-de-Bernardy
15 years ago

try using post_id= 0 for this

#4 @amattie
15 years ago

For what it's worth, post_id 0 won't work without some changes to the get_permalink function as it uses 0 as the default. If you emulate a post object so that you can return 100% custom content, get_permalink needs to be overridden and needs to have a non-zero post ID passed to it.

#5 @Denis-de-Bernardy
15 years ago

can you expand a bit on what you'd like to do? it clear you want to create a fake post of sorts, but it would help understand why in order to make better sense of the ticket...

#6 @amattie
15 years ago

jmabe and I made a product / plugin called dsIDXpress for the company we work for. It makes an API call to our servers for the data and returns the markup in the context of a fake post. We went back and forth between post ID 0 and -1 and ultimately choose -1 because of the get_permalink issue.

Here's the relevant source for the plugin: <http://plugins.svn.wordpress.org/dsidxpress/trunk/client.php>. The Activate function is where the fake post is created.

#7 @Denis-de-Bernardy
15 years ago

try something like this, then:

$post->ID = time();
while ( wp_cache_get($post->ID, 'posts')
  $post->ID += time();

also, don't forget to do the following on the shutdown hook, for memcached users:

wp_cache_delete($post->ID, 'posts');
Note: See TracTickets for help on using tickets.