是的,可以循环使用json并为每个hero条目创建一个页面。这将为每个人创建一个新页面(在内容区域中添加名称作为标题和简历)。如果需要,您可以创建自己的自定义帖子类型,这将使自定义更加容易。https://codex.wordpress.org/Post_Types
jQuery
$(document).ready(function(){
//Get Jason Data- this is for a local file
$.getJSON(\'/hero.json\',function(data) {
// the action name refers to the php wp_ajax_ action
$.post(\'/wp-admin/admin-ajax.php\',{data:data,action:"add_pages"}, function(response) {
//Check teh Ajax Response
console.log(\'Got this from the server: \' + response);
});
});
});
功能。php
function add_pages_function() {
global $wpdb;
// this is how you get access to the database
$data = $_POST[\'data\'];
//loop through json
foreach($data as $d){
echo $d[\'name\'];
//Add pages
$post["id"] = wp_insert_post( array(
"post_title" => $d[\'name\'],
"post_author" => 1,
"post_content" => $d[\'bio\'],
"post_type" => \'page\', //or add \'custom_post_type\' slug
"post_status" => "publish"
));
//UPDATED - for adding meta data (linked custom fields)
update_post_meta( $post["id"],\'my-custom-meta\' , $d[\'super power\'] );
}
wp_die();
}
// uses \'add_pages\' from the action after the wp_ajax
add_action( \'wp_ajax_add_pages\', \'add_pages_function\' );
有关更多wp\\U inerst\\U post选项
https://developer.wordpress.org/reference/functions/wp_insert_post/这没有签入以检查帖子标题是否存在,但这应该是一个良好的开始