I'm creating a wordpress plugin to automatically make a bunch of pages from a dataset I have that I'll covert to an array. Here's my code so far;
<?php
/*
Plugin Name: Create Pages Plugin
Description: a plugin to create pages programatically
Version: 1.0
Author: DJ Khaled
*/
function myplugin_activate() {
global $user_ID;
$array22 = array(
"example1" => "example-1",
"examaple2" => "example-2"
);
foreach ($array22 as $key => $value) {
if (is_admin()){
$page_title = $key;
$page_content = '<p>Hello World</p>';
$page = array(
'post_type' => 'page',
'post_title' => $page_title,
'post_content' => $page_content,
'post_status' => 'publish',
'post_author' => $user_ID,
'post_name' => $value
);
wp_insert_post($page);
}
}
}
register_activation_hook( __FILE__, 'myplugin_activate' );
?>
I'm unsure why these pages aren't created when I activate my plugin. Any help would be appreciated.
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire