Sometimes, you want to use a text area for the Post Content field instead of the default WYSIWYG field. Sure you can create a custom textarea instead but more often than not, what’s inside this won’t show up in your search results or be output as default by your theme. There is some good information in the CRED API but at time of writing it was missing some critical stuff for those new to PHP and the WordPress API. For instance it gives some example code for creating a hook but doesn’t tell you where to put it so you can execute it and that’s a really important bit of information and so I’ve created a mini HOWTO that shows all three steps involved for any newbies like me.
Firstly, in your CRED form add a generic field titled post_content_substitute or whatever you want to call it. Choose “Save to database” in the options and don’t forget to click the update form button. The field should look similar to below in your CRED form.
[cred_generic_field field="post_content_substitute" type="textarea" class="" urlparam=""]
Secondly, we are going to create some code to manipulate our data. In this instance we want to redirect the data entered into the generic textarea field to the post_content field of our post which is in the wp_posts table of our WordPress database. To do this we create the following code:
function my_save_data_action($post_id, $form_data)
// check if CRED form ID 309 is being used and then...
if ($form_data['id']==309) // <------ Put your CRED form ID here.
// scoop up the data from the generic form field and redirect it instead to the post_content field
Thirdly, the important bit. This is how we get our new code executed which is ….by creating our own plugin. You could try to find the relevant functions.php file to put your code into but just one syntax error in there can kill your WP interface and then it’s off to vi. Putting the code in a plugin is much safer and there is less risk of your code being replaced during an update. The plugin wrapper is as follows and the PHP tags are the first and last characters in your file.
Plugin Name: Your plugin name goes here
Description: Your description goes here
Author: Your name
// Your code goes here
Fill in the required plugin information where required above and add your code to it. Put the file into your plugins directory with the same ownership and rights as your other plugin files and then activate the plugin via the plugins interface in wp-admin.
This HOWTO is a combination of information from the CRED API and WordPress Plugin API documentation and various forum posts I found in the WP-Types forums — none of which unfortunately told the whole story so I hope this helps someone.