Skip to main content
19 events
when toggle format what by license comment
Apr 20, 2013 at 19:07 history edited s_ha_dum CC BY-SA 3.0
improved code formatting
Nov 2, 2010 at 10:30 comment added sorich87 Thanks @Denis! I always thought that $post was the latest version depending on the priority order.
Nov 2, 2010 at 10:03 comment added Denis de Bernardy @sorich: exactly.
Nov 1, 2010 at 18:24 comment added sorich87 @Denis, I think I get it: $post does not contain the modifications done by all the other functions hooking in to 'save_post', right?
Nov 1, 2010 at 18:09 vote accept Scott B
Nov 1, 2010 at 18:02 comment added Scott B Here is the question. wordpress.stackexchange.com/questions/3526/…
Nov 1, 2010 at 17:57 comment added Denis de Bernardy @sorich87: in the filtering part of wp, the same object gets passed over and over. By contrast, wp_cache_get() returns a clone of the freshest version on each call - which is then returned by get_post(). When using the $post argument, you're really working on a copy of the post as saved but before any plugin messes around with it.
Nov 1, 2010 at 17:48 comment added sorich87 @Scott B, you can submit you code in another question and we will help you troubleshoot the issue.
Nov 1, 2010 at 17:45 comment added Scott B For example, I have a function that returns the keyword density of the post content. When called on page load it returns accurate value of 2.5%, but when called from within the save_post function it returns 100%, which is why I'm tracking back to the postID. Why would the function return different values depending on where its called from?
Nov 1, 2010 at 17:43 comment added sorich87 @Denis, the $post object passed to do_action('save_post', $post_ID, $post); is actually the results of a $post = get_post($post_ID);. How can it be staled?
Nov 1, 2010 at 17:43 comment added Scott B OK, I think both point to the same content object, though the IDs themselves are different. My core problem though, is I'm getting different values returned from my functions when they are called from the save_post function than when they are called on page load. Its got me stumped...
Nov 1, 2010 at 17:39 comment added Denis de Bernardy @ScottB you're seeing it used both for the post and it's revision. Since revisions were introduced you need to get the post, and check it's type to make sure you're dealing with the one you're looking for.
Nov 1, 2010 at 17:37 comment added Denis de Bernardy Never use the $post parameter. WP stores and sends a different copy in the cache, meaning it could be stale by the time your function gets called.
Nov 1, 2010 at 17:33 comment added sorich87 I am not sure, but I think it has something to do with the post revision. Are the values of $post->post_content and $post->post_title correct?
Nov 1, 2010 at 17:24 comment added Scott B $post_ID and $post->ID are the same. However, the value being returned is in the 300's (increments by one each time i click "Publish" to test). My post id should be 176
Nov 1, 2010 at 17:21 comment added Scott B Every time I test, the value of $post_ID, it gets incremented by one. Its as if this were a draft version ID incrementing. Any ideas?
Nov 1, 2010 at 17:19 comment added sorich87 Do you mean echo $post_ID and echo $post->ID return different results?
Nov 1, 2010 at 17:14 comment added Scott B @sorich: I'm getting an different (and incorrect) value for $post->ID echo inside the "my_save_function" than when its echo'd outside that function. Any ideas?
Nov 1, 2010 at 17:00 history answered sorich87 CC BY-SA 2.5