ACF前端表单wordpress类别不起作用


ACF frontend form wordpress category not working

我正在使用 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"所有字段都被保存,但类别不会在后端保存。

非常感谢

您的帮助。

这应该很直接用

'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' ,
    );  
$term = get_term_by( 'slug', 'your custom term slug', 'your custom taxonomy' );
$term_id = $term->term_id;
'tax_input' => array( 'your taxonomy' => $term_id )

这可能会有所帮助