• Resolved rddt

    (@rddt)


    I want to use a pods form to allow users to create/publish posts from the front end, but because the form is displayed on the front end, users cannot enter a post title. I’d like to have a required field on the form become the post title. What solution(s) would work for this?

Viewing 1 replies (of 1 total)
  • I use this exact setup on my site to create the post title.

    reference here: https://docs.pods.io/code/filter-reference/pods_api_pre_save_pod_item_podname/

    I needed my pods field incident_number to be the post title and slug for the post.

    add_filter( 'pods_api_pre_save_pod_item_incident', 'slug_set_title', 10, 2);
    
    function slug_set_title($pieces, $is_new_item) {
    //only for a new post
    	if(!$is_new_item){
    		return;
    	}
    
      //make sure that all 2 fields are active
      $fields = array( 'post_title', 'incident_number', 'pictometry_url');
      
      foreach( $fields as $field ) {
    
        if ( ! in_array( $field, $pieces[ 'fields_active'] ) ) {
    
          $pieces['fields_active'][] = $field;
    
        }
      }
      
      //set post title using pod field script
      $pieces[ 'object_fields' ][ 'post_title' ][ 'value' ] = $pieces[ 'fields' ][ 'incident_number' ][ 'value' ];
    	
      //return $pieces to save
      return $pieces;
    }
Viewing 1 replies (of 1 total)
  • The topic ‘Pods form field becomes title of post’ is closed to new replies.