Can you use wp_update_post in a shortcode?

[ad_1]

I’m trying to update a target page (not the page the shortcode is on) by calling a shortcode on a specific page. Imagine having two links on your phone for saying “The Ski Slope is Open” or “The Ski Slope is Closed” on a specific page and being able to toggle that by triggering a specific shortcode. Could this be achieved by inserting something like this into the shortcode function:

​

$postId=1011;

$mynewpagedata = array(

‘ID’ => $postId,

‘post\_contnet’ => ‘The Ski Slope is Open’,

);

wp\_update\_post ($mynewpagedata);

​

Any help would be greatly appreciated.

[ad_2]
2 Comments
  1. You spelled content wrong.. Was that the same in your environment?

    So from what I can tell, your trying to make a sign on a page say open or closed, and instead of signing in and doing it manually your trying to visit a second page to activate the switch right?

    wp_update_post( $mynewpostdata, true ); if (is_wp_error($post_id)) { $errors = $post_id->get_error_messages(); foreach ($errors as $error) { echo $error; } }

    See if this echos an error on the page?

    What’s your shortcode look like.

 

This site will teach you how to build a WordPress website for beginners. We will cover everything from installing WordPress to adding pages, posts, and images to your site. You will learn how to customize your site with themes and plugins, as well as how to market your site online.

Buy WordPress Transfer