0

I have a custom field defined as content_from_page. I want to populate the Value of the content_from_page Name with content embedded within the page. I plan to dynamically change the page's content and I want to pass certain dynamic content into the custom field.

I know how to dynamically produce the page but what I want to know if there is a way to pass page content into the Value field of a custom field each time the page is produced.

Thank you!

  • What does content_from_page do? Could you not just use the actual content instead? – Tom J Nowell Jul 2 at 18:33
1

You can see https://codex.wordpress.org/Plugin_API/Action_Reference/save_post for reference.

Here is a quick example of creating/updating meta field when create/updating a page.

function save_page( $post_id, $post, $update ) {

    $post_type = get_post_type( $post_id );

    // If this isn't a 'page' post, don't update it.
    if ( 'page' != $post_type ) return;

    // Update the post's metadata.
    update_post_meta( $post_id, 'content_from_page', $post->post_content );

}
add_action( 'save_post', 'save_page', 10, 3 );

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.