#12446 closed defect (bug) (invalid)
"get_comments" transforms post id
| Reported by: |
|
Owned by: | |
|---|---|---|---|
| Priority: | normal | Milestone: | |
| Component: | General | Version: | |
| Severity: | normal | Keywords: | |
| 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)
Change History (8)
comment:1
follow-up:
↓ 2
Denis-de-Bernardy — 3 years ago
- Milestone Unassigned deleted
- Resolution set to invalid
- Status changed from new to closed
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 :)
try using post_id= 0 for this
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.
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...
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.
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');

the database stores IDs as bigint(20) unsigned.