
{"id":2284,"date":"2013-08-03T01:28:21","date_gmt":"2013-08-03T01:28:21","guid":{"rendered":"http:\/\/tapchicntt.com\/?p=2284"},"modified":"2023-08-10T09:38:36","modified_gmt":"2023-08-10T02:38:36","slug":"wordpress-huong-dan-su-dung-custom-field-cua-wordpress","status":"publish","type":"post","link":"https:\/\/tapchicntt.com\/wordpress-huong-dan-su-dung-custom-field-cua-wordpress\/","title":{"rendered":"[WordPress] H\u01b0\u1edbng d\u1eabn s\u1eed d\u1ee5ng Custom Field c\u1ee7a WordPress"},"content":{"rendered":"\n<p>Custom Field l\u00e0 d\u1eef li\u1ec7u b\u1ed5 sung v\u00e0o m\u1ed7i b\u00e0i vi\u1ebft hay page. M\u00ecnh l\u1ea5y v\u00ed d\u1ee5 th\u1ef1c t\u1ebf nh\u01b0 sau, n\u1ebfu b\u1ea1n mu\u1ed1n ch\u00e8n gi\u00e1 cho m\u1ed9t s\u1ea3n ph\u1ea9m. B\u1ea1n c\u00f3 th\u1ec3 ch\u00e8n m\u1ed9t bi\u1ebfn price cho s\u1ea3n ph\u1ea9m \u0111\u00f3.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">H\u01b0\u1edbng d\u1eabn \u1ee9ng d\u1ee5ng Custom Field<\/h2>\n\n\n\n<p>N\u1ebfu kh\u00f4ng th\u1ea5y th\u00ec c\u00e1c b\u1ea1n c\u00f3 th\u1ec3 t\u00ecm ph\u00eda tr\u00ean tr\u00ecnh duy\u1ec7t:<\/p>\n\n\n\n<p>B\u1ea5m v\u00e0o ch\u1eef Screen Options v\u00e0 tick d\u1ea5u v\u00e0o Custom Field.<\/p>\n\n\n\n<p>Ho\u1eb7c <\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><a href=\"https:\/\/tapchicntt.com\/wp-content\/uploads\/2013\/08\/wordpress-huong-dan-su-dung-custom-field-cua-wordpress-1691634911.png\"><img loading=\"lazy\" decoding=\"async\" width=\"321\" height=\"682\" src=\"https:\/\/tapchicntt.com\/wp-content\/uploads\/2013\/08\/wordpress-huong-dan-su-dung-custom-field-cua-wordpress-1691634911.png\" alt=\"\" class=\"wp-image-8091\" srcset=\"https:\/\/tapchicntt.com\/wp-content\/uploads\/2013\/08\/wordpress-huong-dan-su-dung-custom-field-cua-wordpress-1691634911.png 321w, https:\/\/tapchicntt.com\/wp-content\/uploads\/2013\/08\/wordpress-huong-dan-su-dung-custom-field-cua-wordpress-1691634911-141x300.png 141w\" sizes=\"auto, (max-width: 321px) 100vw, 321px\" \/><\/a><\/figure><\/div>\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><a href=\"https:\/\/tapchicntt.com\/wp-content\/uploads\/2013\/08\/wordpress-huong-dan-su-dung-custom-field-cua-wordpress-1691634932.png\"><img loading=\"lazy\" decoding=\"async\" width=\"784\" height=\"507\" src=\"https:\/\/tapchicntt.com\/wp-content\/uploads\/2013\/08\/wordpress-huong-dan-su-dung-custom-field-cua-wordpress-1691634932.png\" alt=\"\" class=\"wp-image-8092\" srcset=\"https:\/\/tapchicntt.com\/wp-content\/uploads\/2013\/08\/wordpress-huong-dan-su-dung-custom-field-cua-wordpress-1691634932.png 784w, https:\/\/tapchicntt.com\/wp-content\/uploads\/2013\/08\/wordpress-huong-dan-su-dung-custom-field-cua-wordpress-1691634932-300x194.png 300w, https:\/\/tapchicntt.com\/wp-content\/uploads\/2013\/08\/wordpress-huong-dan-su-dung-custom-field-cua-wordpress-1691634932-768x497.png 768w\" sizes=\"auto, (max-width: 784px) 100vw, 784px\" \/><\/a><\/figure><\/div>\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large\"><a href=\"https:\/\/tapchicntt.com\/wp-content\/uploads\/2013\/08\/wordpress-huong-dan-su-dung-custom-field-cua-wordpress-1691635096.png\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"461\" src=\"https:\/\/tapchicntt.com\/wp-content\/uploads\/2013\/08\/wordpress-huong-dan-su-dung-custom-field-cua-wordpress-1691635096-1024x461.png\" alt=\"\" class=\"wp-image-8094\" srcset=\"https:\/\/tapchicntt.com\/wp-content\/uploads\/2013\/08\/wordpress-huong-dan-su-dung-custom-field-cua-wordpress-1691635096-1024x461.png 1024w, https:\/\/tapchicntt.com\/wp-content\/uploads\/2013\/08\/wordpress-huong-dan-su-dung-custom-field-cua-wordpress-1691635096-300x135.png 300w, https:\/\/tapchicntt.com\/wp-content\/uploads\/2013\/08\/wordpress-huong-dan-su-dung-custom-field-cua-wordpress-1691635096-768x345.png 768w, https:\/\/tapchicntt.com\/wp-content\/uploads\/2013\/08\/wordpress-huong-dan-su-dung-custom-field-cua-wordpress-1691635096.png 1056w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/a><\/figure><\/div>\n\n\n<p>B\u00e2y gi\u1edd c\u00e1c b\u1ea1n th\u1eed th\u00eam c\u00e1c tr\u01b0\u1eddng price, discount.<\/p>\n\n\n\n<p>B\u00e2y gi\u1edd ch\u00fang ta b\u1eaft \u0111\u1ea7u l\u1ea5y d\u1eef li\u1ec7u c\u1ee7a c\u00e1c tr\u01b0\u1eddng price, discount.<\/p>\n\n\n\n<p>M\u1edf file <strong>single.php<\/strong> ch\u00e8n v\u00e0o \u0111o\u1ea1n code sau:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: php; title: ; notranslate\" title=\"\">\nthe_meta();\n<\/pre><\/div>\n\n\n<p>Ch\u00fa \u00fd: t\u1ed1t nh\u1ea5t l\u00e0 c\u00e1c b\u1ea1n ch\u00e8n d\u01b0\u1edbi \u0111o\u1ea1n <strong><code>&lt;?php the_content (); ?&gt;<\/code><\/strong><\/p>\n\n\n\n<p>\u0110o\u1ea1n code tr\u00ean s\u1ebd list ra t\u1ea5t Custom Field c\u00f3 trong b\u00e0i vi\u1ebft. Ngo\u00e0i ra, ch\u00fang ta c\u00f3 th\u1ec3 truy xu\u1ea5t t\u1eebng d\u1eef li\u1ec7u trong b\u00e0i vi\u1ebft \u0111\u1ec3 hi\u1ec3n th\u1ecb b\u00e0i vi\u1ebft \u0111\u1eb9p h\u01a1n:<\/p>\n\n\n\n<p>B\u1ea1n s\u1eed d\u1ee5ng h\u00e0m sau \u0111\u1ec3 load d\u1eef li\u1ec7u tao v\u1ecb tr\u00ed b\u1ea1n c\u1ea7n hi\u1ec3n th\u1ecb:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: php; title: ; notranslate\" title=\"\">\nget_post_meta($post_id, $key, $single);\n<\/pre><\/div>\n\n\n<ul class=\"wp-block-list\">\n<li><strong>$post_id<\/strong>: Chu\u1ed7i x\u00e1c \u0111\u1ecbnh ID c\u1ee7a b\u00e0i vi\u1ebft. Th\u00f4ng th\u01b0\u1eddng ch\u00fang ta hay \u0111\u1eb7t gi\u00e1 tr\u1ecb cho chu\u1ed7i n\u00e0y l\u00e0 b\u00e0i vi\u1ebft hi\u1ec7n t\u1ea1i, v\u1eady ch\u00fang ta s\u1ebd g\u00e1n gi\u00e1 tr\u1ecb cho chu\u1ed7i n\u00e0y l\u00e0 $post_id-&gt;ID.<\/li>\n\n\n\n<li><strong>$key<\/strong>: T\u00ean c\u1ee7a Key mu\u1ed1n g\u1ecdi ra. V\u00ed d\u1ee5 (price ho\u1eafc discount)<\/li>\n\n\n\n<li><strong>$single<\/strong>: \u0110\u00e2y l\u00e0 m\u1ed9t gi\u00e1 tr\u1ecb ki\u1ec3u boolean. Chu\u1ed7i n\u00e0y ch\u1ec9 c\u00f3 th\u1ec3 thi\u1ebft l\u1eadp m\u1ed9t trong hai gi\u00e1 tr\u1ecb \u0111\u00f3 l\u00e0 true ho\u1eb7c false.<\/li>\n<\/ul>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: php; title: ; notranslate\" title=\"\">\n$price= get_post_meta($post-&gt;ID, &#039;price&#039;, true);\nif ($price) { echo &#039;Price: &#039; . $price; }\n<\/pre><\/div>\n\n\n<p>T\u01b0\u01a1ng t\u1ef1 v\u1edbi c\u00e1c Key c\u00f2n l\u1ea1i, c\u00e1c b\u1ea1n n\u00ean vi\u1ebft theo gi\u1ed1ng m\u1eabu tr\u00ean. Nh\u1edb h\u00e0m if n\u1eefa nh\u00e9 v\u00ec n\u1ebfu kh\u00f4ng c\u00f3 h\u00e0m if \u1edf tr\u00ean th\u00ec \u1edf c\u00e1c b\u00e0i vi\u1ebft kh\u00e1c s\u1ebd hi\u1ec7n n\u1ed9i dung HTML c\u00f3 trong code m\u1eb7c d\u00f9 kh\u00f4ng ch\u1ee9a custom field n\u00e0o.<\/p>\n\n\n\n<p>Ch\u00fac c\u00e1c b\u1ea1n th\u00e0nh c\u00f4ng.!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Custom Field l\u00e0 d\u1eef li\u1ec7u b\u1ed5 sung v\u00e0o m\u1ed7i b\u00e0i vi\u1ebft hay page. M\u00ecnh l\u1ea5y v\u00ed d\u1ee5 th\u1ef1c t\u1ebf nh\u01b0 [&hellip;]<\/p>\n","protected":false},"author":6,"featured_media":6979,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[137],"tags":[],"class_list":["post-2284","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-wordpress"],"views":412,"_links":{"self":[{"href":"https:\/\/tapchicntt.com\/rest-api\/wp\/v2\/posts\/2284","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/tapchicntt.com\/rest-api\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/tapchicntt.com\/rest-api\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/tapchicntt.com\/rest-api\/wp\/v2\/users\/6"}],"replies":[{"embeddable":true,"href":"https:\/\/tapchicntt.com\/rest-api\/wp\/v2\/comments?post=2284"}],"version-history":[{"count":7,"href":"https:\/\/tapchicntt.com\/rest-api\/wp\/v2\/posts\/2284\/revisions"}],"predecessor-version":[{"id":8095,"href":"https:\/\/tapchicntt.com\/rest-api\/wp\/v2\/posts\/2284\/revisions\/8095"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/tapchicntt.com\/rest-api\/wp\/v2\/media\/6979"}],"wp:attachment":[{"href":"https:\/\/tapchicntt.com\/rest-api\/wp\/v2\/media?parent=2284"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/tapchicntt.com\/rest-api\/wp\/v2\/categories?post=2284"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/tapchicntt.com\/rest-api\/wp\/v2\/tags?post=2284"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}