I want a plugin can create auto page insert into database wordpress. How ?

  • 2
    When the page should be created? – WisdmLabs May 26 '15 at 4:57
  • when install plugin. I see codex only function create post is wp_insert_post, but not insert page – Nguyen Quoc Thang May 26 '15 at 5:00
  • 1
    You can use register_activation_hook to create page on plugin activation. wp_insert_post can be used to create page. you need to pass post_type = 'page' – WisdmLabs May 26 '15 at 5:02
  • Please work on a solution on your own. If you have trouble with it, post your code and we will be happy to help. – s_ha_dum May 26 '15 at 15:04

following hook is called when the plugin is activated from dashboard.

    register_activation_hook( __FILE__, 'myplugin_activate' );
    function myplugin_activate() {
   //create a variable to specify the details of page
       $post = array(     
                 'post_content'   => 'content', //content of page
                 'post_title'     =>'title', //title of page
                 'post_status'    =>  'publish' , //status of page - publish or draft
                 'post_type'      =>  'page'  // type of post
       wp_insert_post( $post ); // creates page

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.