how to use wp_insert_post with array to create multiple page?

145 Views Asked by At

I want a way to create multiple pages at once without duplicating the function wp_insert_post for exemple i have this array

$post_data =[
        [
        "post_title" => "england",
        "post_name" => "england-premier-league",
        'post_content' => "england content",
        'post_status' => 'publish',
        'post_author' => 1,
        'post_type' => 'page',
        'post_parent' => 0 
        ],
        [
        "post_title" => "spain",
        "post_name" => "spain-primera-division",
        'post_content' => "spain content",
        'post_status' => 'publish',
        'post_author' => 1,
        'post_type' => 'page',
        'post_parent' => 0 
        ],
        [
        "post_title" => "italian",
        "post_name" => "italian-league-serie-a",
        'post_content' => "italian content",
        'post_status' => 'publish',
        'post_author' => 1,
        'post_type' => 'page',
        'post_parent' => 0 
        ]
        ];

How can I do that please?

0

There are 0 best solutions below