admin管理员组文章数量:1313822
I am creating a custom post type with custom taxonomies while submitting front-end form for custom post it is creating a post but it is not creating new taxonomies which I have already set just need to add custom taxonomy
<form action='' method="post" id="drop_message">
<div class="input-group">
<div class="first">
<label for="first-name-opt">First Name:</label>
<input type="text" name="name" id="name" placeholder="John Doe" class="tag-msg">
</div>
<div class="middle">
<label for="email">Email:</label>
<input type="email" name="email" id="email" placeholder="[email protected]" class="tag-msg">
</div>
<div class="last">
<label for="birthdate">Date Of Birth:</label>
<input type="text" name="birthdate" id="birthdate" placeholder="DD - MM - YYYY" class="tag-msg">
</div>
<div class="submit">
<input type="submit" name="submit" id="submit" value="Leave a Message">
</div>
</div>
</form>
<?php
if( 'POST' == $_SERVER['REQUEST_METHOD']) {
$name = $_POST['name'];
$email = $_POST['email'];
$birthdate = $_POST['birthdate'];
$post = array(
'post_title' => $title,
'post_content' => $description,
'post_author' => $user,
'post_status' => 'publish',
'post_type' => 'messages',
'tax_input' => array(
$name,
$email,
$birthdate,
),
);
$pid = wp_insert_post( $post );
wp_set_object_terms( $pid, $name, 'name');
wp_set_object_terms( $pid, $email, 'email');
wp_set_object_terms( $pid, $birthdate, 'dob');
}
Can anyone help me out for submitting this fields value as custom taxonomies.
I am creating a custom post type with custom taxonomies while submitting front-end form for custom post it is creating a post but it is not creating new taxonomies which I have already set just need to add custom taxonomy
<form action='' method="post" id="drop_message">
<div class="input-group">
<div class="first">
<label for="first-name-opt">First Name:</label>
<input type="text" name="name" id="name" placeholder="John Doe" class="tag-msg">
</div>
<div class="middle">
<label for="email">Email:</label>
<input type="email" name="email" id="email" placeholder="[email protected]" class="tag-msg">
</div>
<div class="last">
<label for="birthdate">Date Of Birth:</label>
<input type="text" name="birthdate" id="birthdate" placeholder="DD - MM - YYYY" class="tag-msg">
</div>
<div class="submit">
<input type="submit" name="submit" id="submit" value="Leave a Message">
</div>
</div>
</form>
<?php
if( 'POST' == $_SERVER['REQUEST_METHOD']) {
$name = $_POST['name'];
$email = $_POST['email'];
$birthdate = $_POST['birthdate'];
$post = array(
'post_title' => $title,
'post_content' => $description,
'post_author' => $user,
'post_status' => 'publish',
'post_type' => 'messages',
'tax_input' => array(
$name,
$email,
$birthdate,
),
);
$pid = wp_insert_post( $post );
wp_set_object_terms( $pid, $name, 'name');
wp_set_object_terms( $pid, $email, 'email');
wp_set_object_terms( $pid, $birthdate, 'dob');
}
Can anyone help me out for submitting this fields value as custom taxonomies.
Share Improve this question asked Feb 27, 2018 at 12:10 Dharit SoniDharit Soni 1132 silver badges6 bronze badges1 Answer
Reset to default 1Use the fourth parameter in wp_set_object_terms()
and pass true
.
wp_set_object_terms( $pid, $name, 'name', true);
wp_set_object_terms( $pid, $email, 'email', true);
wp_set_object_terms( $pid, $birthdate, 'dob', true);
Though I do find it weird to use taxonomies for name, email and birthdate. I'd recommend to use metadata for this.
See: https://codex.wordpress/Function_Reference/update_post_meta
Taxonomies are meant for categories and tags like objects etc.
本文标签: wpsetobjectterms() not adding new term to custom post and custom taxonomy
版权声明:本文标题:wp_set_object_terms() not adding new term to custom post and custom taxonomy 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741955263a2406952.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论