我们收到了一个URL,它显然是一个JSON文件:
http://www.domain.com/tools/export-json/?destination=hawaii
谈到JSON和Wordpress,我完全不懂。有人知道从哪里开始吗?
我想我们需要从这个JSON文件中创建单独的帖子。。
我们收到了一个URL,它显然是一个JSON文件:
http://www.domain.com/tools/export-json/?destination=hawaii
谈到JSON和Wordpress,我完全不懂。有人知道从哪里开始吗?
我想我们需要从这个JSON文件中创建单独的帖子。。
$slices = json_decode(file_get_contents(\'yourJSONFile.json\'),true);
循环到数据中if ($slices) {
foreach ($slices as $slice) {
$title = $slice[1];
// insert more logic here
}
}
通过使用wp_insert_post. // Create post object
$my_post = array(
\'post_title\' => $title,
\'post_content\' => \'This is my content\',
\'post_status\' => \'publish\',
\'post_author\' => 1,
\'post_category\' => array(8,39)
);
// Insert the post into the database and return the new post ID
$post_id = wp_insert_post( $my_post, true );
if ( is_wp_error( $post_id ) ) {
// error handling....
}
本教程中的更多详细信息:http://tommcfarlin.com/programmatically-create-a-post-in-wordpress/更新:我更改了代码如下$cats = get_categories(); $output = array(\'categories\' => array()); function collect_posts(){ $args = array( \'numberposts=\' => 9999, \'category\' => $cat ); $myposts = get_posts( $args ); foreac