Friday, September 18, 2015

Wordpress- hook to create page

function check_page_feed_page_exist(){
    if( get_page_by_title( 'feed-to-custom-post' ) == NULL ){
    create_pages_feed( 'feed-to-custom-post' );
    }
}


add_action('init','check_page_feed_page_exist');
function create_pages_feed($pageName) {
    $createPage = array(
      'post_title'    => $pageName,
      'post_content'  => 'Starter content',
      'post_status'   => 'publish',
      'post_author'   => 1,
      'post_type'     => 'page',
      'post_name'     => $pageName
    );

    // Insert the post into the database
    wp_insert_post( $createPage );
}

No comments :

Post a Comment