Skip to main content
added 154 characters in body
Source Link
stlawrance
  • 411
  • 1
  • 4
  • 11

I am wondering how should i insert the category programmatically and it should insert only 1 time after the theme is activated.

I know up to here.

function example_insert_category() {
    wp_insert_term(
        'Science',
        'category',
        array(
          'description' => 'This is an Science category.',
          'slug'        => 'science'
        )
    );
}
add_action( 'after_setup_theme', 'example_insert_category' );

i don't know how to insert children etc. I want to insert category structured like this:

Science
--Grade 11
----Science
----Management
----Humanities
--Grade 12
----Science
----Management
----Humanities 

MIT
--Grade 15
----Science
----Management
----Humanities
--Grade 16
----Science
----Management
----Humanities

Is it possible to do programmatically?

Thanks

I am wondering how should i insert the category programmatically and it should insert only 1 time after the theme is activated.

I know up to here.

function example_insert_category() {
    wp_insert_term(
        'Science',
        'category',
        array(
          'description' => 'This is an Science category.',
          'slug'        => 'science'
        )
    );
}
add_action( 'after_setup_theme', 'example_insert_category' );

i don't know how to insert children etc. I want to insert category structured like this:

Science
--Grade 11
----Science
----Management
----Humanities
--Grade 12
----Science
----Management
----Humanities

Is it possible to do programmatically?

Thanks

I am wondering how should i insert the category programmatically and it should insert only 1 time after the theme is activated.

I know up to here.

function example_insert_category() {
    wp_insert_term(
        'Science',
        'category',
        array(
          'description' => 'This is an Science category.',
          'slug'        => 'science'
        )
    );
}
add_action( 'after_setup_theme', 'example_insert_category' );

i don't know how to insert children etc. I want to insert category structured like this:

Science
--Grade 11
----Science
----Management
----Humanities
--Grade 12
----Science
----Management
----Humanities 

MIT
--Grade 15
----Science
----Management
----Humanities
--Grade 16
----Science
----Management
----Humanities

Is it possible to do programmatically?

Thanks

Source Link
stlawrance
  • 411
  • 1
  • 4
  • 11

Inserting Category programmatically

I am wondering how should i insert the category programmatically and it should insert only 1 time after the theme is activated.

I know up to here.

function example_insert_category() {
    wp_insert_term(
        'Science',
        'category',
        array(
          'description' => 'This is an Science category.',
          'slug'        => 'science'
        )
    );
}
add_action( 'after_setup_theme', 'example_insert_category' );

i don't know how to insert children etc. I want to insert category structured like this:

Science
--Grade 11
----Science
----Management
----Humanities
--Grade 12
----Science
----Management
----Humanities

Is it possible to do programmatically?

Thanks