Editing and Updating Custom Fields from Frontend

While Editus offers a way to add custom tags to the post settings dialog, it now offers another way to support editing and saving of custom fields.

Let’s say you are using the Advanced Custom Fields plugin. And your post/page has the following content:


<div id="field1-div">
[acf field="field1"]
</div>

This will display the content of the custom field/metadata named “field1” inside the div with the id “field1-div”

To have it editable and saveable, add the following PHP code:

function my_custom_fields( $data ) {
    return array('field1' => '#field1-div');
}
add_filter( 'editus_custom_fields', 'my_custom_fields', 10, 1 );

As you can see, your filter function should return an array with field names and the element selector.

When the post is saved, the custom fields will be updated.

You can also combine “Read Only Items” and “Disable Post Saving” options. If “Disable Post Saving” is on, the content of the post will not be altered when you hit the Save button, but the custom fields will still update. You can use “Read Only Items” to specify the elements that should not be edited by users, such as labels.