Reputation: 3804
Calling this from a plugin:
$my_post = array(
'post_title' => 'Test',
'post_content' => 'Testing wp_insert_post()'
);
wp_insert_post($my_post);
results in a long error message:
Fatal error: Uncaught Error: Call to undefined function is_user_logged_in() in C:\Program Files (x86)\Ampps\www\dev\wordpres....
Can anyone explain why and how to make this work please?
Upvotes: 2
Views: 1589
Reputation: 21691
If you are trying this code out side of WP structure then you need to place require_once("path/to/wordpress/wp-load.php");
inclussion at top of the page.
But if not then you need to check your plugin. You can take a ride here
Upvotes: 2