ACF前端形式wordpress类别不起作用

时间:2014-08-23 10:03:29

标签: php wordpress advanced-custom-fields

我正在使用acf前端表单来创建帖子。所有的字段都在工作,但在前端我想要一个字段,它应该自动将后端的类别设置为帖子。

我有自定义帖子类型名称“人”。

要从前端表单添加帖子,这里是代码

    // Create a new post
$post = array(
    'post_status'  => 'draft' ,
    'post_title'  => $_POST['fields']['field_53c8f0941cec0'] ,
    'post_category'  =>  array(43,47) ,
    'post_type'  => 'person' ,
    'submit_value'  => 'Submit' ,
);  

// insert the post
$post_id = wp_insert_post( $post ); 

。  我的“人”自定义帖子类型的自定义分类名称是“person_type” 所有字段都会保存,但类别不会保存在后端。

非常感谢你的帮助。

2 个答案:

答案 0 :(得分:1)

这应该是非常直接的 使用

'tax_input'      => array( 'CUSTOM_TAXONOMY_NAME' => array( COMMA SEPARTED VALUES OF TERMS)),

实施例

  $post = array(
        'post_status'  => 'Pending' ,
        'post_title'  => $new_title ,
        'post_type'  => 'products' ,
        'tax_input'      => array( 'products_type' => array( 11,33)),
        'post_content' => $contentBlock,
        'submit_value'  => 'Submit' ,
    );  

答案 1 :(得分:0)

$term = get_term_by( 'slug', 'your custom term slug', 'your custom taxonomy' );

$term_id = $term->term_id;

'tax_input' => array( 'your taxonomy' => $term_id )

这可能会有所帮助

相关问题