{"id":10821629,"date":"2018-10-27T12:50:11","date_gmt":"2018-10-27T12:50:11","guid":{"rendered":"https:\/\/wordpress.org\/support\/?post_type=helphub_article&#038;p=10821629"},"modified":"2025-08-02T08:33:10","modified_gmt":"2025-08-02T08:33:10","slug":"assign-custom-fields","status":"publish","type":"helphub_article","link":"https:\/\/wordpress.org\/documentation\/article\/assign-custom-fields\/","title":{"rendered":"Assign custom fields"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">WordPress has the ability to allow post authors to assign custom fields to a post. This arbitrary extra information is known as <strong>metadata<\/strong>. This <strong>metadata<\/strong> can include bits of information such as:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Mood:<\/strong> Happy<\/li>\n\n\n\n<li><strong>Currently Reading:<\/strong> Cinderella<\/li>\n\n\n\n<li><strong>Listening To:<\/strong> Rock Around the Clock<\/li>\n\n\n\n<li><strong>Weather:<\/strong> Hot and humid<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">With some extra coding, it is possible to achieve more complex actions, such as using the <strong>metadata<\/strong> to store an expiration date for a post.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Metadata is handled with <strong>key\/value<\/strong> pairs. The <strong>key<\/strong> is the name of the metadata element. The <strong>value<\/strong> is the information that will appear in the metadata list on each individual post that the information is associated with.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Keys<\/strong> can be used more than once per post. For example, if you were reading two different books (perhaps a technical book at work and a fiction at home), you could create a &#8220;reading&#8221; key and use it twice on the same post, once for each book.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Here is an example of what this information might look like on your post:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><strong>Currently Reading<\/strong>: <em>Calvin and Hobbes<\/em><br><strong>Today's Mood<\/strong>: <em>Jolly and Happy<\/em><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Displaying Custom Fields in the Block Editor<\/h2>\n\n\n\n<figure class=\"wp-block-image alignright size-medium\" style=\"margin-right:var(--wp--preset--spacing--40);margin-left:var(--wp--preset--spacing--40)\"><img loading=\"lazy\" decoding=\"async\" width=\"177\" height=\"300\" src=\"https:\/\/wordpress.org\/documentation\/files\/2018\/10\/custom-fileds-1-6.8-177x300.jpg\" alt=\"Option button and Preferences menu  in the sidebar\" class=\"wp-image-16365959\" srcset=\"https:\/\/wordpress.org\/documentation\/files\/2018\/10\/custom-fileds-1-6.8-177x300.jpg 177w, https:\/\/wordpress.org\/documentation\/files\/2018\/10\/custom-fileds-1-6.8-605x1024.jpg 605w, https:\/\/wordpress.org\/documentation\/files\/2018\/10\/custom-fileds-1-6.8.jpg 610w\" sizes=\"auto, (max-width: 177px) 100vw, 177px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">In the Block Editor, Custom Fields area is hidden by default if they have not been used before. To display the area, follow the below steps.<\/p>\n\n\n\n<p class=\"has-background wp-block-paragraph\" style=\"background-color:#e5f5fa\">Note: Before displaying the Custom Fields area, make sure your content is saved since page reload is required for this option change.<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Click Options button (three dots icon) at the right of the top toolbar.<\/li>\n\n\n\n<li>Select Preferences<\/li>\n\n\n\n<li>Select General tab and turn on the Custom fields in the Advanced section<\/li>\n\n\n\n<li>Click Select &amp; Reload Page button<\/li>\n<\/ol>\n\n\n\n<figure class=\"wp-block-image aligncenter size-full is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"1502\" height=\"722\" src=\"https:\/\/wordpress.org\/documentation\/files\/2018\/10\/cusom-fields-2-6.8.jpg\" alt=\"Custom fields in the Preferences panel\" class=\"wp-image-16365960\" style=\"aspect-ratio:2.0803651704820525;width:508px;height:auto\" srcset=\"https:\/\/wordpress.org\/documentation\/files\/2018\/10\/cusom-fields-2-6.8.jpg 1502w, https:\/\/wordpress.org\/documentation\/files\/2018\/10\/cusom-fields-2-6.8-300x144.jpg 300w, https:\/\/wordpress.org\/documentation\/files\/2018\/10\/cusom-fields-2-6.8-1024x492.jpg 1024w, https:\/\/wordpress.org\/documentation\/files\/2018\/10\/cusom-fields-2-6.8-768x369.jpg 768w\" sizes=\"auto, (max-width: 1502px) 100vw, 1502px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">You&#8217;ll see Custom Fields in the bottom of the Block Editor.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Usage<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Based upon our example above, let&#8217;s add two custom fields, one called &#8220;Currently Reading&#8221; and the other &#8220;Today&#8217;s Mood&#8221;. Please follow the below steps to add this information to a post using Custom Fields.<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>To create a new <strong>Custom Field<\/strong> called &#8220;Currently Reading&#8221;, click Enter new button, enter the text &#8220;Currently Reading&#8221; (without the quotes) in the text entry field titled <strong>Name<\/strong>.<\/li>\n\n\n\n<li>The newly created <strong>Key<\/strong> (&#8220;Currently Reading&#8221;) should now be assigned a <strong>Value<\/strong>, which in our case is the name of the book currently being read, &#8220;Calvin and Hobbes&#8221;. Type &#8220;Calvin and Hobbes&#8221; in the <em>Value<\/em> field, again without the quotes.<\/li>\n\n\n\n<li>Click <strong>Add Custom Field<\/strong> button to save this custom information for that post.<\/li>\n<\/ol>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"658\" height=\"294\" src=\"https:\/\/wordpress.org\/documentation\/files\/2018\/10\/custom_field_example.jpg\" alt=\"\" class=\"wp-image-10821652\" srcset=\"https:\/\/wordpress.org\/documentation\/files\/2018\/10\/custom_field_example.jpg 658w, https:\/\/wordpress.org\/documentation\/files\/2018\/10\/custom_field_example-300x134.jpg 300w\" sizes=\"auto, (max-width: 658px) 100vw, 658px\" \/><figcaption class=\"wp-element-caption\">Custom Fields<\/figcaption><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">To add your &#8220;Today&#8217;s Mood&#8221;, repeat the process and add &#8220;Today&#8217;s Mood&#8221; to the <strong>key<\/strong> and a description of your mood in the <strong>value<\/strong> text boxes and click <strong>Add Custom Field <\/strong>to save this information with the post.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">On your next post, you can add a new book and mood to your metadata. In the <strong>Custom Fields<\/strong> section, the <strong>Key<\/strong> will now feature a pull-down list with the previously entered Custom Fields. Choose &#8220;Currently Reading&#8221; and then enter the new book you are reading in the <strong>value<\/strong>. Click <strong>Add Custom Field<\/strong> and then repeat the process to add &#8220;Today&#8217;s Mood&#8221;.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">You only need to create a new &#8220;KEY&#8221; <strong>once<\/strong>, after which you can assign a value to that key for every post, if you so desire. You can also assign more than one <em>Value<\/em> to a key, for a post. This will come in handy for people who read more than one book at a time.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Displaying Custom Fields on the front end<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">To display the Custom Fields for each post, you have to use a template tag that customizes your theme. For more details about it, please refer to:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/developer.wordpress.org\/reference\/functions\/the_meta\/\">the_meta() <\/a>&#8211; Template tag that automatically lists all Custom Fields of a post<\/li>\n\n\n\n<li><a href=\"https:\/\/developer.wordpress.org\/reference\/functions\/get_post_custom\/\">get_post_custom()<\/a> and <a href=\"https:\/\/developer.wordpress.org\/reference\/functions\/get_post_meta\/\">get_post_meta()<\/a> &#8211; Retrieves one or all metadata of a post.<\/li>\n\n\n\n<li><a href=\"https:\/\/developer.wordpress.org\/reference\/functions\/get_post_custom_values\/\">get_post_custom_values()<\/a> &#8211; Retrieves values for a custom post field.<\/li>\n\n\n\n<li><a href=\"https:\/\/developer.wordpress.org\/themes\/basics\/template-tags\/\">Template Tags<\/a> &#8211; WordPress Theme Developers Handbook page on Template Tags<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">You may install a plugin that manages custom fields by searching &#8220;<a href=\"https:\/\/wordpress.org\/plugins\/search\/custom+fields\/\">custom fields<\/a>&#8221; in the plugins directory.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>WordPress has the ability to allow post authors to assign custom fields to a post. This arbitrary extra information is known as metadata. This metadata can include bits of information such as: With some extra coding, it is possible to achieve more complex actions, such as using the metadata to store an expiration date for [&hellip;]<\/p>\n","protected":false},"author":14216496,"featured_media":0,"menu_order":0,"comment_status":"open","ping_status":"closed","template":"","meta":{"advanced_seo_description":"","jetpack_seo_html_title":"","jetpack_seo_noindex":false},"category":[81,80],"class_list":["post-10821629","helphub_article","type-helphub_article","status-publish","hentry","category-appearance","category-customization"],"revision_note":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/wordpress.org\/documentation\/wp-json\/wp\/v2\/articles\/10821629","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wordpress.org\/documentation\/wp-json\/wp\/v2\/articles"}],"about":[{"href":"https:\/\/wordpress.org\/documentation\/wp-json\/wp\/v2\/types\/helphub_article"}],"author":[{"embeddable":true,"href":"https:\/\/wordpress.org\/documentation\/wp-json\/wp\/v2\/users\/14216496"}],"replies":[{"embeddable":true,"href":"https:\/\/wordpress.org\/documentation\/wp-json\/wp\/v2\/comments?post=10821629"}],"version-history":[{"count":2,"href":"https:\/\/wordpress.org\/documentation\/wp-json\/wp\/v2\/articles\/10821629\/revisions"}],"predecessor-version":[{"id":16365961,"href":"https:\/\/wordpress.org\/documentation\/wp-json\/wp\/v2\/articles\/10821629\/revisions\/16365961"}],"wp:attachment":[{"href":"https:\/\/wordpress.org\/documentation\/wp-json\/wp\/v2\/media?parent=10821629"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/wordpress.org\/documentation\/wp-json\/wp\/v2\/category?post=10821629"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}