admin管理员组文章数量:1424916
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 badges1 Answer
Reset to default 1that 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.
本文标签: post metaAdding Custom MetaData
版权声明:本文标题:post meta - Adding Custom MetaData 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745426144a2658121.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论