Book Image

WordPress Web Application Development

By : Rakhitha Nimesh Ratnayake
Book Image

WordPress Web Application Development

By: Rakhitha Nimesh Ratnayake

Overview of this book

Table of Contents (19 chapters)
WordPress Web Application Development Second Edition
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Persisting custom field data


You already know that default fields and taxonomies are automatically saved to the database on post publish. In order to complete the project creation process, we need to save the custom field data to the metatables. As usual, we have to update the constructor to add the necessary actions to match the following code:

public function __construct($template_parser) {
  // Instance variable initializations
  // Other actions
  add_action('save_post', array($this, 'save_project_meta_data'));
}

WordPress doesn't offer an out-of-the-box solution for form validation as most websites don't have complex forms. This becomes a considerable limitation in web applications. So, let's explore the possible workarounds to reduce these limitations. The action save_post inside the constructor will only be called once the post is saved to the database with default field data. We can do the necessary validations and processing for custom fields inside the function defined for the save_post...