+6 votes
909 views
in Programming by (11.7k points)
I want to create a new post in wordpress without dashboard with a single non-wordpress php file, how can I add a new post?

1 Answer

+7 votes
by (10.4k points)

Firstly create a php file in root folder of wordpress directory

Include wp-load.php ->

<?php include "wp-load.php"; ?>

and

$new_ date= mktime(23,31,0,9,2,2014); /* hour, minute, second, month, day, year */
$new_ date=date("Y-m-d G:i:s", $new_ date);
 
 
$new_post = array(
'post_title' =>  $title,
'post_content' => $text,
'post_status' => 'publish', /* or future*/
'post_date' => $new_date,
'post_author' => 1, /* author id*/
'post_type' => 'post', /* post type*/
'post_category' => array($category_id) /* you can use multiple categories so : array(1,3,5) */
);
 

wp_insert_post($new_post);

Ask a Question
Welcome to WikiTechSolutions where you can ask questions and receive answers from other members of the community.

You can ask a question without registration.

Categories

...