pods_api_post_save_pod_item_{podname}
Called after any Pod item is saved for a specific Pod.
Usage
<?php
add_action('pods_api_post_save_pod_item_my_pod_name', 'my_post_save_function', 10, 3);
function my_post_save_function($pieces, $is_new_item, $id) {
Parameters
Parameter | Type | Details |
---|---|---|
$pieces | (array) | |
$is_new_item | (boolean) | |
$id | (integer) | ID of item being updated |
Examples
Update Taxonomy With Value Of Field Related To Taxonomy
Takes the value of a single-select field 'genre' related to the taxonomy 'genres' and updates the taxonomy with the term set in the 'genre' field from the custom post type 'films'.
<?php
add_action( 'pods_api_post_save_pod_item_my_pod_name', 'my_custom_pods_update_terms_on_save', 10, 3 );
/**
* Update post terms on save for another associated taxonomy.
*
* @param array $pieces List of data.
* @param boolean $is_new_item Whether the item is new.
* @param int $id Item ID.
*/
function my_custom_pods_update_terms_on_save( $pieces, $is_new_item, $id ) {
// Get the value of a single select Relationship field.
$term = (int) $pieces['fields']['my_relationship_field']['value'];
// Set $term to null to avoid errors if no value set.
if ( empty( $term ) ) {
$term = null;
}
// Set the term for an associated taxonomy with $term.
wp_set_object_terms( $id, $term, 'my_other_taxonomy', false );
}
Update Post Author To Current User
<?php
add_action( 'pods_api_post_save_pod_item_my_pod_name', 'my_custom_pods_update_post_author_on_save', 10, 3 );
/**
* Update post author on save to the current user ID.
*
* @param array $pieces List of data.
* @param boolean $is_new_item Whether the item is new.
* @param int $id Item ID.
*/
function my_custom_pods_update_post_author_on_save( $pieces, $is_new_item, $id ) {
if ( ! wp_is_post_revision( $id ) ) {
// Avoid recursion loops on saving.
pods_no_conflict_on( 'post' );
$user_id = get_current_user_id();
$post_data = array(
'ID' => $id,
'post_author' => $user_id,
);
wp_update_post( $post_data );
// Avoid recursion loops on saving.
pods_no_conflict_off( 'post' );
}
}
Action/Filter Related To
Related Actions/Filters
Additional Information
- This is the last filter called in save_pod_item()
- save_pod_item() (and thus, this filter) will only be called for WordPress objects if you have added one or more fields to the Pod.