admin管理员组文章数量:1312662
The following runs through a cron job and successfully creates and publishes the post to a custom category.
However, it does not attach a custom taxonomy (ap_job_status
) term (ID 3
) to the post.
$args = array(
'post_author' => $post_author_id,
'post_date' => $job['date'],
'post_content' => $job['desc'],
'post_title' => $job['title'],
'post_name' => $job['ref'] . '-' . $job['title'],
'post_status' => 'publish',
'post_type' => 'ap_job_listings',
'meta_input' => array(
'ap_ref' => $job['ref'],
'ap_consultant' => $job['consultant'],
'ap_role' => $job['role'],
'ap_contract' => $job['contract'],
'ap_salary' => $job['salary'],
'ap_salary_period' => $job['period'],
'ap_skills' => $job['skills'],
'ap_location' => $job['location'],
),
);
$post_id = wp_insert_post($args);
$tax = 'ap_job_status';
$term = get_term_by( 'id', array(3), $tax);
wp_set_object_terms($post_id, $term, $tax);
I have also (unsuccessfully) tried adding the following to the $args
and not using the wp_set_object_terms
method...
'tax_input' => array('ap_job_status' => array(3)),
Some points to note...
1) 'post_author' will alway be an administrator
2) Taxonomy in not hierarchical
Code for custom taxonomy is here (just in case its relevant)
add_action( 'init', 'ap_job_status_taxonomy');
function ap_job_status_taxonomy() {
register_taxonomy(
'ap_job_status',
'ap_job_listings',
array(
'hierarchical' => false,
'label' => 'Job Status',
'show_admin_column' => true,
'query_var' => true,
'exclude_from_search' => false,
'rewrite' => array(
'slug' => 'status',
'with_front' => false
)
)
);
}
Thanks in advance for your help!
本文标签: wp insert postwpinsertpost not adding taxonomy (using wpsetobjectterms)
版权声明:本文标题:wp insert post - wp_insert_post not adding taxonomy (using wp_set_object_terms) 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741914264a2404629.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论