WordPress.org

Ready to get started?Download WordPress

Forums

Pods - Custom Content Types and Fields
[resolved] Presave Function - Edit Post Title (8 posts)

  1. unity3software
    Member
    Posted 6 months ago #

    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://wordpress.org/plugins/pods/

  2. Josh Pollock
    Member
    Plugin Author

    Posted 6 months ago #

    What fields will determine the title?

  3. unity3software
    Member
    Posted 6 months ago #

    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?

  4. unity3software
    Member
    Posted 6 months ago #

    The POD is created from a custom post type

  5. Josh Pollock
    Member
    Plugin Author

    Posted 6 months ago #

    Check out the docs for the pre_save filter:
    http://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";

  6. Gattermeier
    Member
    Posted 6 months ago #

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

  7. unity3software
    Member
    Posted 6 months ago #

    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 );
  8. Gattermeier
    Member
    Posted 5 months ago #

    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?

Reply

You must log in to post.

About this Plugin

About this Topic