pods_api_pre_save_pod_item_{podname}
Called before any Pod item is saved for a specific Pod.
Usage
<?php
add_filter('pods_api_pre_save_pod_item_my_pod_name', 'my_pre_save_function', 10, 2);
function my_pre_save_function($pieces, $is_new_item) {
Parameters
Parameter | Type | Details |
---|---|---|
$pieces | (array) | |
$is_new_item | (boolean) |
Examples
Change a field value
<?php
add_filter('pods_api_pre_save_pod_item_', 'my_pre_save_function', 10, 2);
function my_pre_save_function($pieces, $is_new_item) {
$pieces[ 'fields' ][ 'my_field' ][ 'value' ] = "some value";
return $pieces;
}
Prevent post update if a field has an undesired value
This example checks the value of a number field to ensure it is greater than zero. If it is greater than zero $pieces is returned, which allows the post to be updated. If not wp_die is used to throw an error and prevent post updating.
<?php
add_filter('pods_api_pre_save_pod_item_', 'slug_num_not_zero', 10, 2);
function slug_num_not_zero($pieces, $is_new_item) {
//get the value of the 'number_of_things' field into $num
$num = $pieces[ 'fields' ][ 'number_of_things' ][ 'value' ];
//if $num is greater than 0 return, which updates post.
if ( $num > 0 ) {
return $pieces;
}
else {
//if not throw an error.
wp_die( 'You shall not pass!');
}
}
Action/Filter Related To
Additional Information
- This is the first 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.