-
-
Save eichgi/0005ab4fba93e00397009999a7dbecf5 to your computer and use it in GitHub Desktop.
Como insertar publicaciones en WP
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Load WordPress | |
require_once '../wp-load.php'; | |
require_once ABSPATH . '/wp-admin/includes/taxonomy.php'; | |
// Set the timezone so times are calculated correctly | |
date_default_timezone_set('Europe/London'); | |
// Create post | |
$titulo = $_POST['titulo']; | |
$cotenido = $_POST['contenido']; | |
/*$id = wp_insert_post(array( | |
'post_title' => $title, | |
'post_content' => $content, | |
'post_date' => date('Y-m-d H:i:s'), | |
'post_author' => $user_id, | |
'post_type' => 'post', | |
'post_status' => 'publish', | |
));*/ | |
$id = wp_insert_post(array( | |
'post_title' => 'TITULOX2', | |
'post_content' => 'CONTENIDOX2', | |
'post_date' => date('Y-m-d H:i:s'), | |
'post_author' => 1, | |
'post_type' => 'post', | |
'post_status' => 'publish', | |
)); | |
if ($id) { | |
// Set category - create if it doesn't exist yet | |
wp_set_post_terms($id, wp_create_category('My Category'), 'category'); | |
// Add meta data, if required | |
add_post_meta($id, 'meta_key', $metadata); | |
echo json_encode(["status" => "OK"]); | |
} else { | |
echo "WARNING: Failed to insert post into WordPress\n"; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment