• Resolved unity3software

    (@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?

    https://www.ads-software.com/plugins/pods/

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

    (@shelob9)

    What fields will determine the title?

    Thread Starter unity3software

    (@unity3software)

    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?

    Thread Starter unity3software

    (@unity3software)

    The POD is created from a custom post type

    Plugin Contributor Josh Pollock

    (@shelob9)

    Check out the docs for the pre_save filter:
    https://pods.io/docs/code/filter-reference/pods_api_pre_save_pod_item_podname/

    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.

    Thread Starter unity3software

    (@unity3software)

    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.