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!
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!
Share Improve this question asked Jul 2, 2019 at 16:35 Pat E.Pat E. 1 1 |1 Answer
Reset to default 1You can see https://codex.wordpress/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 );
content_from_page
do? Could you not just use the actual content instead? – Tom J Nowell ♦ Commented Jul 2, 2019 at 18:33