Title: wp_post_update in shortcode
Last modified: November 28, 2022

---

# wp_post_update in shortcode

 *  [Joseph](https://wordpress.org/support/users/fullstack1995/)
 * (@fullstack1995)
 * [3 years, 6 months ago](https://wordpress.org/support/topic/wp_post_update-in-shortcode/)
 * hi im trying to update post in shortcode, but cause infinite loop.
 *     ```
       add_action( 'init', function()
       {
           add_shortcode( 'test', 'test_callback' );
       } );
   
       function test_callback()
       {
           wp_update_post( ['ID' => get_the_ID()] );
       }
       ```
   
 * the problem is with the
    `do_action( 'wp_insert_post', $post_ID, $post, $update);`

Viewing 7 replies - 1 through 7 (of 7 total)

 *  [catacaustic](https://wordpress.org/support/users/catacaustic/)
 * (@catacaustic)
 * [3 years, 6 months ago](https://wordpress.org/support/topic/wp_post_update-in-shortcode/#post-16242488)
 * What are you actually trying to achive with this? There’s probably a betterway
   to do it then what you have now.
 * If that’s all of the code that you’re using it doens’t make any sense as you’re
   only setting an ID in the update request.
 *  Thread Starter [Joseph](https://wordpress.org/support/users/fullstack1995/)
 * (@fullstack1995)
 * [3 years, 6 months ago](https://wordpress.org/support/topic/wp_post_update-in-shortcode/#post-16242677)
 * thanks for replay [@catacaustic](https://wordpress.org/support/users/catacaustic/)
 * im using yaost (news seo) addones for my website.
    and im trying to update the
   post in site-map.xml
 *  [catacaustic](https://wordpress.org/support/users/catacaustic/)
 * (@catacaustic)
 * [3 years, 6 months ago](https://wordpress.org/support/topic/wp_post_update-in-shortcode/#post-16242695)
 * But what are you trying to update? As I said, in your code you aren’t updating
   anything at all, just supplying a post ID.
 * If you can’t work out what you need you woudl be better off asking or support
   from Yoast. As that’s a commercial plugin, it’s not supported here.
 *  Thread Starter [Joseph](https://wordpress.org/support/users/fullstack1995/)
 * (@fullstack1995)
 * [3 years, 6 months ago](https://wordpress.org/support/topic/wp_post_update-in-shortcode/#post-16242710)
 * looks like you dont know much about wp functions, this method without giving 
   the post_date, it will update it
 *  [catacaustic](https://wordpress.org/support/users/catacaustic/)
 * (@catacaustic)
 * [3 years, 6 months ago](https://wordpress.org/support/topic/wp_post_update-in-shortcode/#post-16242717)
 * The information that you wanted to update the post date when it is viewed was
   what I asked before, but you didn’t mention that part, so I stil didn’t know 
   what you actually wanted to do.
 * So, do you want to do this only for specific posts when they are viewed, or all
   posts?
 * Remember, the more information that you can give us the more that we can help.
   When we don’t know what you want to actually do, it’s almost impossible to figure
   out your intentions from an obscure code snippet.
 *  Thread Starter [Joseph](https://wordpress.org/support/users/fullstack1995/)
 * (@fullstack1995)
 * [3 years, 6 months ago](https://wordpress.org/support/topic/wp_post_update-in-shortcode/#post-16242727)
 * im trying to update post date by wp hooks itself to work for others plugins to
   work properly.
    i can update post date by other methods, but only hooks work 
   for me.
 *  Moderator [bcworkz](https://wordpress.org/support/users/bcworkz/)
 * (@bcworkz)
 * [3 years, 6 months ago](https://wordpress.org/support/topic/wp_post_update-in-shortcode/#post-16244869)
 * There’s nothing about the shortcode itself that causes an infinite loop. Your
   theme or a plugin has hooked into one of the save post actions where the callback
   is causing shortcodes in content to be processed. The code you posted works as
   intended on my test site. No infinite looping.

Viewing 7 replies - 1 through 7 (of 7 total)

The topic ‘wp_post_update in shortcode’ is closed to new replies.

 * In: [Developing with WordPress](https://wordpress.org/support/forum/wp-advanced/)
 * 7 replies
 * 3 participants
 * Last reply from: [bcworkz](https://wordpress.org/support/users/bcworkz/)
 * Last activity: [3 years, 6 months ago](https://wordpress.org/support/topic/wp_post_update-in-shortcode/#post-16244869)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
