{"id":3661,"date":"2009-09-03T12:34:46","date_gmt":"2009-09-03T19:34:46","guid":{"rendered":"http:\/\/css-tricks.com\/?p=3661"},"modified":"2010-03-02T06:38:04","modified_gmt":"2010-03-02T13:38:04","slug":"using-custom-fields","status":"publish","type":"page","link":"https:\/\/css-tricks.com\/snippets\/wordpress\/using-custom-fields\/","title":{"rendered":"Using Custom Fields"},"content":{"rendered":"

Dump out all custom fields as a list<\/h4>\n
<?php the_meta(); ?><\/code><\/pre>\n

Display value of one specific custom field<\/h4>\n
<?php echo get_post_meta($post->ID, 'mood', true); ?><\/code><\/pre>\n

“mood” would be ID value of custom field<\/p>\n

Display multiple values of same custom field ID<\/h4>\n
<?php $songs = get_post_meta($post->ID, 'songs', false); ?>\r\n<h3>This post inspired by:<\/h3>\r\n<ul>\r\n\t<?php foreach($songs as $song) {\r\n\t\techo '<li>'.$song.'<\/li>';\r\n\t} ?>\r\n<\/ul><\/code><\/pre>\n

Display custom field only if exists (logic)<\/h4>\n
<?php \r\n    $url = get_post_meta($post->ID, 'snippet-reference-URL', true); \r\n\r\n\tif ($url) {\r\n\t    echo \"<p><a href='$url'>Reference URL<\/a><\/p>\";\r\n\t}\r\n?><\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"

Dump out all custom fields as a list <?php the_meta(); ?> Display value of one specific custom field <?php echo get_post_meta($post->ID, ‘mood’, true); ?> “mood” would be ID value of custom field Display multiple values of same custom field ID <?php $songs = get_post_meta($post->ID, ‘songs’, false); ?> <h3>This post inspired by:<\/h3> <ul> <?php foreach($songs as […]<\/p>\n","protected":false},"author":3,"featured_media":0,"parent":3229,"menu_order":0,"comment_status":"open","ping_status":"closed","template":"page-snippet.php","meta":{"_bbp_topic_count":0,"_bbp_reply_count":0,"_bbp_total_topic_count":0,"_bbp_total_reply_count":0,"_bbp_voice_count":0,"_bbp_anonymous_reply_count":0,"_bbp_topic_count_hidden":0,"_bbp_reply_count_hidden":0,"_bbp_forum_subforum_count":0,"sig_custom_text":"","sig_image_type":"featured-image","sig_custom_image":0,"sig_is_disabled":false,"inline_featured_image":false,"c2c_always_allow_admin_comments":false,"footnotes":""},"tags":[],"acf":[],"jetpack-related-posts":[{"id":4612,"url":"https:\/\/css-tricks.com\/snippets\/wordpress\/dump-all-custom-fields\/","url_meta":{"origin":3661,"position":0},"title":"Dump All Custom Fields","date":"November 5, 2009","format":false,"excerpt":"WordPress has a built in function, the_meta(), for outputting all custom fields. But this function is limited in that it doesn't always output all of them. For example, it misses custom fields added by plugins which begin with an _ underscore. This bit of code uses an alternate function, get_post_custom()\u2026","rel":"","context":"In "Article"","img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":193131,"url":"https:\/\/css-tricks.com\/video-screencasts\/136-moving-things-cms-needed\/","url_meta":{"origin":3661,"position":1},"title":"#136: Moving Things to a CMS as Needed","date":"January 19, 2015","format":false,"excerpt":"In this video, I prattle on about a particular \"real world\" situation I was in involving how I handle the CodePen Meetups page. At the very beginning days of CodePen Meetups, we just had a single one planned. It was to be the first ever CodePen Meetup in Austin, Texas.\u2026","rel":"","context":"With 12 comments","img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":20514,"url":"https:\/\/css-tricks.com\/lodge\/artists-website\/028-events-admin-and-ui\/","url_meta":{"origin":3661,"position":2},"title":"#028 – Events, Admin and UI","date":"March 12, 2013","format":false,"excerpt":"We learned how to do a custom loop and output custom data from our custom post types and custom fields in the last video. This time we need to do it again, only for the slightly more complex Events section. We'll need a custom page template just for the events\u2026","rel":"","context":"With 3 comments","img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":4566,"url":"https:\/\/css-tricks.com\/snippets\/wordpress\/custom-loop-based-on-custom-fields\/","url_meta":{"origin":3661,"position":3},"title":"Custom Loop\/Query Based on Custom Fields","date":"October 30, 2009","format":false,"excerpt":"Last updated by Jason Witt. If you design or develop WordPress themes or plugins, there's a good chance that someday you'll need to make a query for custom meta fields. These are those completely custom key\/value pairs that you can attach to any post, page, or custom post type. WordPress\u2026","rel":"","context":"In "Article"","img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":2957,"url":"https:\/\/css-tricks.com\/video-screencasts\/65-advanced-uses-for-custom-fields-in-wordpress\/","url_meta":{"origin":3661,"position":4},"title":"#65: Advanced Uses for Custom Fields in WordPress","date":"June 23, 2009","format":false,"excerpt":"More than any other single feature, what makes WordPress a CMS (as opposed to just a blogging platform) is custom fields. Custom fields are chunks of data that travel along with posts and pages in key\/value pairs. This data can be pulled out and used in your templates as you\u2026","rel":"","context":"In "Article"","img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":4053,"url":"https:\/\/css-tricks.com\/snippets\/wordpress\/recent-posts-function\/","url_meta":{"origin":3661,"position":5},"title":"Recent Posts Function","date":"September 13, 2009","format":false,"excerpt":"Technique #1 This function is useful when you need to display content, excerpt, custom fields, or anything related to the post beyond it's link and title. If you just need a list of linked titles, see the next technique. Put the following function in functions.php function recent_posts($no_posts = 10, $excerpts\u2026","rel":"","context":"In "Article"","img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]}],"_links":{"self":[{"href":"https:\/\/css-tricks.com\/wp-json\/wp\/v2\/pages\/3661"}],"collection":[{"href":"https:\/\/css-tricks.com\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/css-tricks.com\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/css-tricks.com\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/css-tricks.com\/wp-json\/wp\/v2\/comments?post=3661"}],"version-history":[{"count":4,"href":"https:\/\/css-tricks.com\/wp-json\/wp\/v2\/pages\/3661\/revisions"}],"predecessor-version":[{"id":5792,"href":"https:\/\/css-tricks.com\/wp-json\/wp\/v2\/pages\/3661\/revisions\/5792"}],"up":[{"embeddable":true,"href":"https:\/\/css-tricks.com\/wp-json\/wp\/v2\/pages\/3229"}],"wp:attachment":[{"href":"https:\/\/css-tricks.com\/wp-json\/wp\/v2\/media?parent=3661"}],"wp:term":[{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/css-tricks.com\/wp-json\/wp\/v2\/tags?post=3661"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}