acf_field_taxonomy::save_post
This function will save any terms in the save_post_terms array
Method of the class: acf_field_taxonomy{}
No Hooks.
Returns
null. Nothing (null).
Usage
$acf_field_taxonomy = new acf_field_taxonomy(); $acf_field_taxonomy->save_post( $post_id );
- $post_id(int) (required)
- .
Changelog
| Since 5.0.9 | Introduced. |
acf_field_taxonomy::save_post() acf field taxonomy::save post code ACF 6.0.4
function save_post( $post_id ) {
// Check for saved terms.
if ( ! empty( $this->save_post_terms ) ) {
/**
* Determine object ID allowing for non "post" $post_id (user, taxonomy, etc).
* Although not fully supported by WordPress, non "post" objects may use the term relationships table.
* Sharing taxonomies across object types is discouraged, but unique taxonomies work well.
* Note: Do not attempt to restrict to "post" only. This has been attempted in 5.8.9 and later reverted.
*/
$decoded = acf_decode_post_id( $post_id );
$type = $decoded['type'];
$id = $decoded['id'];
if ( $type === 'block' ) {
// Get parent block...
}
// Loop over taxonomies and save terms.
foreach ( $this->save_post_terms as $taxonomy => $term_ids ) {
wp_set_object_terms( $id, $term_ids, $taxonomy, false );
}
// Reset storage.
$this->save_post_terms = array();
}
}