WordPress.org

Ready to get started?Download WordPress

Forums

can any one test this at his installation? code test for auto creation of pages (3 posts)

  1. asafche
    Member
    Posted 3 years ago #

    in the functions.php file of the default theme for the sub-blogs.

    add_action('wpmu_activate_blog','my_default_pages');
    
    function my_default_pages(){
    
    	$default_pages = array('Home','About','Contact');
        	$existing_pages = get_pages();
    
    	foreach($existing_pages as $page){
            	$temp[] = $page->post_title;
            }
    
    	$pages_to_create = array_diff($default_pages,$temp);
    
    	foreach($pages_to_create as $new_page_title){
    
    		// Create post object
    	        $my_post = array();
    	        $my_post['post_title'] = $new_page_title;
    	        $my_post['post_content'] = 'This is my '.$new_page_title.' page.';
    	        $my_post['post_status'] = 'publish';
    	        $my_post['post_type'] = 'page';
    
    	        // Insert the post into the database
    	        $result = wp_insert_post( $my_post );
            }
    }

    what do you say? any suggestions about why it doesn't work?
    it supposed to be very simple...

    thanks,
    asaf.

  2. asafche
    Member
    Posted 3 years ago #

    hi,
    thanks, but it's not exactly what i needed.

    all i want is to create 3 pages as defaults. the plugin doesn't have the option to create pages.

    why the code above isn't working?
    when i change the action to "wp_head" just for checking the function, it does work. like here: origin of code

    why is the action "wpmu_activate_blog" or just "activate_blog" isn't working with this function?

    what have i did wrong?

    cheers,
    asafche.

Topic Closed

This topic has been closed to new replies.

About this Topic