Sunday, September 25, 2022
HomeWordPress DevelopmentDevelop theme with demo default content material, programmatically create pages

Develop theme with demo default content material, programmatically create pages


use after_setup_theme create your submit and tags then save the info, add possibility key and solely run your setup as soon as,

i.e.

add_action( 'after_setup_theme',  perform() {
    
    $setupKey = 'my_theme_activated';

    $setupAlreadyRun = get_option($setupKey);

    if ( $setupAlreadyRun )
        return;

    my_theme_setup( $setupKey );

});


perform my_theme_setup( $setupKey ) {
    $posts = [
        [
            'post_title'        => 'Project Page',
            'post_type'         => 'page',
            'post_status'       => 'publish'
        ],
        [
            'post_title'        => 'Another Project Page',
            'post_type'         => 'page',
            'post_status'       => 'publish'
        ],
        [
            'post_title'        => 'Another Last Project Page',
            'post_type'         => 'page',
            'post_status'       => 'publish'
        ]
    ];

    $postIDs = [];

    foreach( $posts as $submit ) {
        $postIDs[] = wp_insert_post( $submit );
    }

    $tag = wp_insert_term('My Mission Tag', 'post_tag');

    // What else you wish to do right here.



    //Save information in choices desk in case you wish to do one thing with the automated setup ids, 
    if ( is_array( $tag ) && isset( $tag['term_id'] ) )
        update_option('my_auto_setup_tag', $tag['term_id']);

    update_option('my_auto_setup_pages', implode(',', $postIDs ) );
    update_option($setupKey, 1 );
}

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments