• Joseph

    (@fullstack1995)


    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)
  • 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

    (@fullstack1995)

    thanks for replay @catacaustic

    im using yaost (news seo) addones for my website.
    and im trying to update the post in site-map.xml

    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

    (@fullstack1995)

    looks like you dont know much about wp functions, this method without giving the post_date, it will update it

    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

    (@fullstack1995)

    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

    (@bcworkz)

    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.