admin管理员组文章数量:1326447
I was using set_post_type( $post_id, 'post' );
to create the post in type post
from a form. But now I want to submit the form in two post types- post
and asd
.
I was using set_post_type( $post_id, 'post' );
to create the post in type post
from a form. But now I want to submit the form in two post types- post
and asd
.
1 Answer
Reset to default 1Your best bet would be hooking into the post type transition and creating the second (custom) post (type) via PHP. Here is a function that can accomplish just that:
// Automatically create a news (regular post in category ID 1 = news) when a wiki post (custom post type) has been published
function nxt_create_news($new_status, $old_status, $nxt_wiki_post) {
if('publish' === $new_status && 'publish' !== $old_status && $nxt_wiki_post->post_type === 'wiki') {
$nxt_post_author = $nxt_wiki_post->post_author;
$nxt_wiki_permalink = get_post_permalink($nxt_wiki_id);
$nxt_wiki_title = $nxt_wiki_post->post_title;
$nxt_postarr = array(
'post_author' => $nxt_post_author,
'post_content' => 'The wiki entry ' . $nxt_wiki_title . ' has just been published.<br /><br /><a href="' . $nxt_wiki_permalink . '" title="' . $nxt_wiki_title . '">Check out wiki entry</a>.',
'post_title' => 'The wiki entry ' . $nxt_wiki_title . ' has been published',
'post_status' => 'publish',
'post_category' => array(1),
);
$nxt_post_id = wp_insert_post($nxt_postarr);
set_post_thumbnail(get_post($nxt_post_id), '1518');
}
}
add_action( 'transition_post_status', 'nxt_create_news', 10, 3 );
For you, it might be the other way round. You'd create a custom post type after a regular post in some specific category has been created. I hope the example above provides enough context, but just ask if you need more input.
本文标签: pluginsSubmit posts in two different post types with the same form
版权声明:本文标题:plugins - Submit posts in two different post types with the same form 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742211708a2433832.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
psot
andasd
at the same time. What are you trying to fix/solve by doing this? – Tom J Nowell ♦ Commented Aug 4, 2020 at 15:45