post meta - Adding Custom MetaData

In Professional Wordpress Design & Development the author states that WordPress features a simple function to add ne

In Professional Wordpress Design & Development the author states that WordPress features a simple function to add new post metadata called add_post_meta().

This function will attach a piece of metadata to the post as follows:

   <?php  add_post_meta ( $post_id, $meta_key, $meta_value, $unique ); ?>

I've tried adding this code to my functions.php file without the < ? php ? > , and nothing happens. Where would this code go to successfully add a custom metadata box to a post?

In Professional Wordpress Design & Development the author states that WordPress features a simple function to add new post metadata called add_post_meta().

This function will attach a piece of metadata to the post as follows:

   <?php  add_post_meta ( $post_id, $meta_key, $meta_value, $unique ); ?>

I've tried adding this code to my functions.php file without the < ? php ? > , and nothing happens. Where would this code go to successfully add a custom metadata box to a post?

Share Improve this question asked Jun 7, 2019 at 23:17 WestWest 211 silver badge6 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 1

that function is explained here and if I understand it right, it's not quite THAT simple. To use it as a single line in functions, you would have to fill out all those variables.

 add_post_meta ( 7, 'fruit', 'banana' )

This would literally output only on the admin of Post ID 7, and it would create a field called "fruit" with the value of "banana".

So it's simple...in the fact that it can be used in a more complex function to create post meta boxes. You would need to run this in a loop to get it to attach to every post, and depending on how robust you want your fields to be. I'm also not sure if it saves (it looks to me like you need to write that functionality in).

If you're looking to add custom meta boxes to your posts, I HIGHLY recommend using Advanced Custom Fields. You don't need Pro to use it, though it's 100% worth the purchase. It will easily assign to all posts of a type, or to individual posts and pages, it saves when edited, and it's got great documentation for how to call the data into your templates.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745426145a4627186.html

相关推荐

  • post meta - Adding Custom MetaData

    In Professional Wordpress Design & Development the author states that WordPress features a simple function to add ne

    4小时前
    40

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信