pods_api_pre_save_pod_item_{podname}

Called before any Pod item is saved for a specific Pod.

Called before any Pod item is saved for a specific Pod.

<?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!'); 
        } 
    }

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.

Other Helpful Documentation on Filter Reference

pods_field_pick_object_data_params

/** * Overwrite parameters used by PodsField_Pick::get_object_data. * * @since 2.7.21 * * @param array $object_params { * Get object parameters * * @type string $name Field name. * @type mixed $value Current value. * @type array $options Field options. * @type array $pod Pod data. * @type int|string $id Current item ID. * @type …

Read more