megumi / wp-post-helper
0.5.0
2014-12-23 20:07 UTC
Requires
- php: >=5.3
This package is not auto-updated.
Last update: 2024-09-24 04:32:45 UTC
README
wp_insert_post()
的辅助类
安装
在项目根目录中创建一个 composer.json 文件。
{
"require": {
"megumi/wp-post-helper": "*"
}
}
文档
基本用法
$args = array(
'post_name' => 'slug', // slug
'post_author' => '1', // author's ID
'post_date' => '2012-11-15 20:00:00', // post date and time
'post_type' => 'post', // post type (you can use custom post type)
'post_status' => 'publish', // post status, publish, draft and so on
'post_title' => 'title', // post title
'post_content' => 'content', // post content
'post_category'=> array( 1, 4 ), // category IDs in an array
'post_tags' => array( 'tag1', 'tag2' ), // post tags in an array
);
$helper = new Megumi\WP\Post\Helper( $args );
$post_id = $helper->insert();
附件
$args = array(
...
);
$helper = new Megumi\WP\Post\Helper( $args );
$post_id = $helper->insert();
$attachment_id = $helper->add_media(
'http://placehold.jp/100x100.png', // path or url
'title',
'description',
'caption',
false
);
向自定义字段添加值
$args = array(
...
);
$helper = new Megumi\WP\Post\Helper( $args );
$post_id = $helper->insert();
$post->add_meta(
'meta_key', // meta key
'meta_val', // meta value
true // add it as unique (true) or not (false)
);
以高级自定义字段格式添加值
$args = array(
...
);
$helper = new Megumi\WP\Post\Helper( $args );
$post_id = $helper->insert();
$post->add_field(
'field_xxxxxxxxxxxxx', // key
'field_val' // value
);
贡献
克隆此项目。
$ git clone git@github.com:megumiteam/wp-post-helper.git
运行测试
在本地初始化测试环境
(您需要已经安装 mysql、svn 和 wget)
$ bash bin/install-wp-tests.sh wordpress_test root '' localhost latest
安装 phpunit。
$ composer install
单元测试文件位于 tests/
目录。
要运行单元测试,只需执行
$ phpunit