How to set the post excerpt when creating or editing a post

Created by Phil Kurth, Modified on Wed, 29 Mar 2023 at 03:09 PM by Phil Kurth

You may customise the post author (and many other properties) of a post using the af/form/editing/post_data filter. This filter will apply when creating or editing a post using Advanced Forms Pro form.


The following snippet demonstrates how to take the value from a submitted field and assign it to the post except using the filter:


<?php
add_filter( 'af/form/editing/post_data', function ( $post_data, $form, $args ) {

  // Check if this is the correct form. If not, return the post data as is.
  if ( $form['key'] !== '{YOUR_FORM_KEY}' ) {
    return $post_data;
  }

  // Set the post excerpt
  $post_data['post_excerpt'] = af_get_field( '{YOUR_FIELD_NAME_OR_KEY}' );

  return $post_data;
}, 10, 3 );

Was this article helpful?

That’s Great!

Thank you for your feedback

Sorry! We couldn't be helpful

Thank you for your feedback

Let us know how can we improve this article!

Select atleast one of the reasons

Feedback sent

We appreciate your effort and will try to fix the article