wp_insert_post()函数用法

Published
April 28, 2022
浏览次数 :  2

add_action('admin_head', 'insertPetPosts');

function insertPetPosts() {
  for ($i = 0; $i < 10; $i++) {
    $pet = generatePet();

    wp_insert_post(array(
      'post_type' => 'pet',
      'post_title' => $pet['name'],
      'post_status' => 'publish',
      'meta_input' => array(
        'species' => $pet['species'],
        'favFood' => $pet['favFood'],
        'birthYear' => $pet['birthyear'],
        'weight' => $pet['weight'],
        'favColor' => $pet['favColor'],
        'favHobby' => $pet['favHobby']
        )
    ));
  }
}

Top