Skip Navigation

[Closed] Build post body off form data

The Toolset Community Forum is closed, for technical support questions, please head on to our Toolset Professional Support (for paid clients), with any pre-sale or admin question please contact us here.
This support ticket is created 8 years, 8 months ago. There's a good chance that you are reading advice that it now obsolete.
This is the community support forum for Types plugin, which is part of Toolset. Toolset is a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients and people who registered for Types community support can post in it.

Sun Mon Tue Wed Thu Fri Sat
- - 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00
- - - - - - -

Supporter timezone: Asia/Ho_Chi_Minh (GMT+07:00)

This topic contains 3 replies, has 2 voices.

Last updated by Beda 8 years, 8 months ago.

Assisted by: Beda.

Author
Posts
#323572

I am trying to generate the post body from fields a user submits in the CRED form.

I need the post data to show up in Mailchimp. But it will not pick up custom fields. So I would like to generate the body of a post...I currently generate my post title off two fields (Author and Book Title) so I'm hoping it can be done here as well.

And I would like it to be formatted like my view...but instead of being different fields, be automatically generated on submit. I realize this will end up being hardcoded in the post, and I'm ok with that.

Here is my view:

<div style="float:left;margin-right:18px;">[wpv-post-featured-image size="medium" output="url"]</div>
				<span style="font-size: 19px; font-weight:bold !important; color:black;">[types field="book-title"][/types]</span></br>
				<span style="font-size: 16px; font-weight:bold !important; font-style:italic;">by [types field="author"][/types]</span></br>
				<div align="right"><button style="background-color:#713772; height:40px; width:200px; border:1; outline-color:white;">[types field="amazon" title="GRAB IT FOR [types field="sales-price" format= $FIELD_VALUE][/types]!" no_protocol="true" target="_blank" style="color: #dfb84f; font-size: 16px; font-weight:bold !important;" ][/types]</button></div>
		<div style="color:black; font-weight:bold !important;">[types field="blurb"][/types]</div>
		<div style="color:#713772; font-size: 16px; font-weight:bold !important; margin-top: 0px;">Free with Kindle Unlimited? [types field="kindle-unlimited"][/types]</div>
		<div>This <font color=red size=4>[types field="genres" separator=", "][/types]</font> deal is available until [types field="free-day-end" style="text" format="F j, Y"][/types]</div>
  <div style="clear:both"></div>

Here is a link to what that looks like hidden link

My CRED form is at: hidden link

#323577

I was hoping for something like this...but WordPress didn't like it. And it errored.

function build_body($post_id, $formdata)
{
  $field1=get_post_meta($post_id, 'wpcf-book-title');
  $field2=get_post_meta($post_id, 'wpcf-author');
  $field3=get_post_meta($post_id, 'wpcf-post-excerpt');
  $field4=get_post_meta($post_id, 'wpcf-sales-price');
  $field4=get_post_meta($post_id, 'wpcf-genres');
  
  if ($formdata['id']==18) {
    $post_body="$field1[0] by $field2[0]". $field3[0] Get this book for $field4[0]. <font color=red size=4>$field5[0];
    $category = array( 308 );
  }
    
  wp_set_post_categories( $post_id, $category );
  wp_update_post(array('ID'=>$post_id, 'post_body'=>$post_body));
}
#323703

Anyone? Bueller? lol

#323805

Thanks for the Details

I am not sure what you try to achieve.

Are you customizing single.php?

And you want in your single.php (post template) the content you submit with a CRED Form?

First of all, you a hove code, which seems to be a CRED creed_save_data action, is not closing up and would need to be refactored as the below example:
(note, this is a code that inserts a new post upon submitting a certain CRED form)

function my_save_data_action( $post_id, $form_data ) {
       
        // if a specific form, change the ID accordingly
        if ( $form_data['id'] == 95 ) {
 
                //get some data to use later on

                //We are retrieving the post we are editing with this CRED form
                $book_content = get_post( $post_id );
                $summary = get_post_meta( $post_id, 'wpcf-summary', true );

                //Authors in my case are Taxonomies
                $authors = get_the_terms( $post_id, 'book-authors' );
 
                //get authors
                $auth = array();
                foreach( $authors as $author ) {
                        $auth[] = $author->name;
                }
 
                //insert the post
                wp_insert_post( array(
                        'post_title' => sprintf( 'New book is now available: %s', $book_content->post_title ),
                        'post_status' => 'publish',
                        'post_content' => sprintf( 'A new book has been added, %s by %s. <br /><br /><strong>Summary:</strong> %s', $book_content->post_title, join(', ', $auth ), $summary )
                ) );
        }
}
add_action('cred_save_data', 'my_save_data_action',10,2);

You will see how I concatenate the different contents to re-use in my new post.

Is this going into the direction you are heading to?

Please let me know if you have further questions regarding the issue mentioned in this Thread

Thank you for your patience.

The topic ‘[Closed] Build post body off form data’ is closed to new replies.