Support » Plugin: Pods - Custom Content Types and Fields » Presave Function – Edit Post Title

  • Resolved unity3software


    In my custom POD settings, I have unchecked the Title field because my custom fields will ultimately determine what the title is.

    At this stage, all of the records in list view are showing up as “Auto Draft. Obviously because it is hidden from the user. Screen shots

    How can I change the post_title during the ‘pre_save_pod_item’ action?

Viewing 7 replies - 1 through 7 (of 7 total)
  • Plugin Contributor Josh Pollock


    What fields will determine the title?

    My custom fields that I have defined via PODS. But to the question, how best can I access the post_title field during ‘pre_save_pod_item’ action?

    The POD is created from a custom post type

    Plugin Contributor Josh Pollock


    Check out the docs for the pre_save filter:

    You should be able to set, in your pre_save filter, to set the post title value with $pieces[ 'fields' ][ 'post_title' ][ 'value' ] = "WHATEVER_YOU_WANT_TITLE_TO_BE";

    How would that work? I tried this via functions.php, but I am still getting the same “Auto Drafts” for all items.

    Josh, pods_api_pre_save_pod_item does not work because $pieces[‘fields’] only refers to custom meta fields. The default post fields such as ‘post_title’ are only found in: $pieces[‘object_fields’]. However, these only appear to be field descriptors because there is no ‘value’ property to any of these fields.

    Gattermeier, here is my current hack for this POD bug. Hook into the ‘wp_insert_post_data’ filter, which runs for every post add/edit/update. To access the metadata, use: $postarr[ ‘pod_meta_%my_meta_name%’]. By the way, this filter runs BEFORE pods_api_pre_save_pod_item.

    function wp_pre_save( $data , $postarr ) {
        //$data['post_title'] = $postarr['pods_meta_width'].'x'.$postarr['pods_meta_length'];
        if ($data['post_type'] == 'metal_building') {
            $width = $postarr['pods_meta_width'];
            $length = $postarr['pods_meta_length'];
            if (!empty($width) && !empty($length)) {
                $data['post_title'] = $data['post_name'] = $width.'x'.$length;
        return $data;
    add_filter( 'wp_insert_post_data', array($this,'wp_pre_save'), '99', 2 );

    Thank you unity3software. However, trying to add this has a peculiar effect. Suddenly I am not able anymore to save any post, yet alone publish. The functionality seems limited to “submit for review” for all content types, including posts and pages.
    Any idea?

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Presave Function – Edit Post Title’ is closed to new replies.