Insert post from PHP script
-
Hello,
How can i insert a post from a PHP file.
Please give me a working “wp_insert_post” example.Thanks
bye
-
// Create post object $my_post = array( 'post_title' => wp_strip_all_tags( $_POST['post_title'] ), 'post_content' => $_POST['post_content'], 'post_status' => 'publish', 'post_author' => 1, 'post_category' => array( 8,39 ) ); // Insert the post into the database wp_insert_post( $my_post );but first need some include, right?
if yes what kind of files need to include?I don’t see what includes you are talking about and I would need much more info to understand your problem.
what are you going to use the insert for?
do you have a lot of posts that you are trying to bulk insert once or is it some kind of functionality that fires after a certain event?
I need to understand your need to be able to answer you accordinglly.Okay, i want to insert post to wordpress from PHP file.
When i open the “mydomain.com/testinsert.php” that script will post the content to db and the wordpress will show it…ok, try adding this to your php file:
require("wp-includes/post.php");<?php
ini_set(‘display_errors’, 1);
error_reporting(E_ALL);require(“wp-includes/post.php”);
// Create post object
$my_post = array(
‘post_title’ => “qwe”,
‘post_content’ => wp_strip_all_tags($content),
‘post_status’ => ‘publish’,
‘post_author’ => ‘1’,
‘post_category’ => array( 1,2 )
);wp_insert_post( $my_post );
?>
If your question has been answered, we would love if you would mark this topic as resolved in the right hand sidebar. This helps our volunteers find the topics that still need attention and more people will get helped, possibly like you did.
still not answered, i dont know still how can i insert post to my wordpress 🙁
well you just copied the code and put it here so I assumed you found the solution.
did you try this code? what happened if you did?yes i tried, but the error is:
“Fatal error: Call to undefined function wp_strip_all_tags() in /home/penzker/public_html/test.php on line 11”Wait, you’re trying to use WordPress outside of WordPress?
okay, start again, my question is how can i insert post to my wordpress from PHP file?
What do you mean by “post”?
We have no knowledge of your system that you’re running outside of WordPress. If your external system creates posts then you need to tell us how it does it.
ok thx
The topic ‘Insert post from PHP script’ is closed to new replies.