最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Is it possible to populate a custom field with content from a page

programmeradmin1浏览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!

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
  • What does content_from_page do? Could you not just use the actual content instead? – Tom J Nowell Commented Jul 2, 2019 at 18:33
Add a comment  | 

1 Answer 1

Reset to default 1

You 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 );
发布评论

评论列表(0)

  1. 暂无评论