admin管理员组文章数量:1323336
I have a custom post called "Sector" and another called "Areas". When a Sector
is created, around 6 predefined Areas
need to be created as well and linked with the Sector
. To make this relation work, i am using Advanced Custom Fields plugin.
This is the pseudo-algorithm:
add_action('pseudo_hook', 'my_func');
function my_func($sector_id){
$area_titles = array("Living Room", "Kitchen", "Room 1", "Room 2", "Room 3", "Bathroom 1");
$areas = array();
foreach($area_titles as $title){
$areas[] = create_area($title=$title) // pretend it is wp_insert_post() here;
}
// relate created areas to this sector
update_field("areas", $areas, "sector_" . $sector_id) // ACF function to update metafield;
}
My doubts:
Doing some research, i found the
publish_[my_post_type]
hook; but it doesn't fit my purpose since it is triggered also when a post is edited. I need something that runs only within creation.I'd like some feedback about the performance of this approach. It won't be used often, but certainly it will be more than 6 predefined
Areas
in the future.
Since i'm not an Wordpress expert, i'd be very grateful for better ideas.
Thanks in advance
本文标签: pluginsCreate multiple posts when a custom post is created
版权声明:本文标题:plugins - Create multiple posts when a custom post is created 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742136768a2422405.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论