Insert VLP programmatically by shortcode on form submission
-
I would like to pass a link from a form submission and programmatically update the post content with a shortcode
$content1 = '[visual-link-preview type="external" url="'.esc_url($_POST['article1']) .'"]';
but this results in an error. For the block, all i need to do is call the URL and it retrieves and generates the visual link preview. For the shortcode, it does not (as you mentioned). Hence, I suggested that I think this is a useful feature.In the interim, how would you suggest I achieve what I was looking to do? is there a way for me to insert it via code such that it pulls the headline/excerpt/image and saves it to the post without manual intervention?$content1 = '[visual-link-preview type="external" url="'.esc_url($_POST['article1']) .'"]'; // article1 is a URL submitted by users // other code if(wp_insert_post( array( 'post_title' => esc_url_raw($_POST['article1']), 'post_content' => $content1, // this is what i want to achieve 'post_type' => 'article', 'post_status' => 'draft' ) )) // other code
When I try the above code (calling the shortcode just with an external url) my front end throws up a few notices in debug mode, which implies that i did not pass in these variables (but not sure why i need to since this is not a documented requirement for the shortcode):
Notice: Undefined property: stdClass::$title in ms_wp/wp-content/plugins/visual-link-preview/includes/public/class-vlp-link.php on line 53
Notice: Undefined property: stdClass::$summary in ms_wp/wp-content/plugins/visual-link-preview/includes/public/class-vlp-link.php on line 54
Notice: Undefined property: stdClass::$template in ms_wp/wp-content/plugins/visual-link-preview/includes/public/class-vlp-link.php on line 55
- The topic ‘Insert VLP programmatically by shortcode on form submission’ is closed to new replies.