我确实需要添加post\\u meta:
add_post_meta( $insert_q_key_id, \'q_key_type\', (int)$q_key_type ); // Q Key Type
对于ACF:
update_field( "field_52c737a413e07", (int)$q_key_type, $insert_q_key_id ); // Q Key Type
wp\\u set\\u object\\u术语涵盖了答案“应”的其余部分:
wp_set_object_terms( $insert_q_key_id, (int)$q_key_type, \'q_key_type\', true );
然而,在我需要的时候,该函数还没有完全可用,所以答案是为该函数创建一个简单的替换:
/**
* simple wp_set_object_terms replacement as not available during API call
*
* @since 0.4
* @global Object $wpdb
* @param integer $object_id
* @param integer $tt_id
* @return Mixed Integer of inserted row on success | Boolean false
*/
public function q_wp_set_object_terms( $object_id = null, $tt_id = null )
{
if ( ! $object_id || ! $tt_id ) { return false; }
global $wpdb;
if ( $wpdb->insert( $wpdb->term_relationships, array( \'object_id\' => (int)$object_id, \'term_taxonomy_id\' => (int)$tt_id ) ) ) {
return $wpdb->insert_id;
}
// if not ##
return false;
}
我可以使用静态类实例调用它(在我的例子中,该方法是单独类的一部分…):
Q_Key::q_wp_set_object_terms ( $insert_q_key_id, (int)$q_key_type );