{"id":1888,"date":"2017-07-31T04:48:50","date_gmt":"2017-07-31T04:48:50","guid":{"rendered":"http:\/\/docs.contentviewspro.com\/?p=1888"},"modified":"2023-12-27T09:59:42","modified_gmt":"2023-12-27T09:59:42","password":"","slug":"format-custom-field-number","status":"publish","type":"docs","link":"https:\/\/contentviewspro.com\/documentation\/article\/format-custom-field-number\/","title":{"rendered":"Format a numeric custom field value"},"content":{"rendered":"<p>Content Views Pro helps you to show any WordPress custom fields (including ACF, Pods, Types&#8230;) easily.<br \/>\nYou may need to format a numeric custom field value (for example, show a number in price format). To do it, please add this code to file <strong>functions.php<\/strong> of your active WordPress theme:<\/p>\n<pre style=\"font-size:13px\">\n\/\/ Content Views Pro - format a numeric custom field value\nadd_filter( 'pt_cv_ctf_value', 'cvp_theme_ctf_format_value', 100, 3 );\nfunction cvp_theme_ctf_format_value( $args, $key, $post ) {\n\tif ( $key == 'FIELD_NAME' ) {\n\t\t\/\/ Format the number\n\t\t$decimals\t     = 0;\n\t\t$decimals_point\t     = '.';\n\t\t$thousands_separator = ',';\n\t\t$formated_value\t     = number_format( (float) $args, $decimals, $decimals_point, $thousands_separator );\n\n\t\t\/\/ Add \"$\" before number, add \"USD\" after number\n\t\t$args = sprintf( '$ %s USD', $formated_value );\n\t}\n\n\treturn $args;\n}\n<\/pre>\n<p>Please replace <strong>FIELD_NAME<\/strong> with name of your custom field.<\/p>\n<p>Best regards,<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Content Views Pro helps you to show any WordPress custom fields (including ACF, Pods, Types&#8230;) easily. You may need to format a numeric custom field value (for example, show a number in price format). To do it, please add this code to file functions.php of your active WordPress theme: \/\/ Content Views Pro &#8211; format &hellip;<\/p>\n<p class=\"read-more\"> <a class=\"\" href=\"https:\/\/contentviewspro.com\/documentation\/article\/format-custom-field-number\/\"> <span class=\"screen-reader-text\">Format a numeric custom field value<\/span> Read More &raquo;<\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"site-sidebar-layout":"default","site-content-layout":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","footnotes":""},"doc_category":[52],"doc_tag":[13,21],"class_list":["post-1888","docs","type-docs","status-publish","hentry","doc_category-custom-field","doc_tag-custom-field","doc_tag-custom-code"],"year_month":"2026-09","word_count":135,"total_views":"1","reactions":{"happy":"0","normal":"0","sad":"0"},"author_info":{"name":"CVP","author_nicename":"cvp","author_url":"https:\/\/contentviewspro.com\/documentation\/author\/cvp\/"},"doc_category_info":[{"term_name":"Custom Field (core, ACF, Metabox, etc.)","term_url":"https:\/\/contentviewspro.com\/documentation\/cats\/custom-field\/"}],"doc_tag_info":[{"term_name":"custom field","term_url":"https:\/\/contentviewspro.com\/documentation\/tags\/custom-field\/"},{"term_name":"custom PHP code","term_url":"https:\/\/contentviewspro.com\/documentation\/tags\/custom-code\/"}],"_links":{"self":[{"href":"https:\/\/contentviewspro.com\/documentation\/wp-json\/wp\/v2\/docs\/1888","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/contentviewspro.com\/documentation\/wp-json\/wp\/v2\/docs"}],"about":[{"href":"https:\/\/contentviewspro.com\/documentation\/wp-json\/wp\/v2\/types\/docs"}],"author":[{"embeddable":true,"href":"https:\/\/contentviewspro.com\/documentation\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/contentviewspro.com\/documentation\/wp-json\/wp\/v2\/comments?post=1888"}],"version-history":[{"count":2,"href":"https:\/\/contentviewspro.com\/documentation\/wp-json\/wp\/v2\/docs\/1888\/revisions"}],"predecessor-version":[{"id":5398,"href":"https:\/\/contentviewspro.com\/documentation\/wp-json\/wp\/v2\/docs\/1888\/revisions\/5398"}],"wp:attachment":[{"href":"https:\/\/contentviewspro.com\/documentation\/wp-json\/wp\/v2\/media?parent=1888"}],"wp:term":[{"taxonomy":"doc_category","embeddable":true,"href":"https:\/\/contentviewspro.com\/documentation\/wp-json\/wp\/v2\/doc_category?post=1888"},{"taxonomy":"doc_tag","embeddable":true,"href":"https:\/\/contentviewspro.com\/documentation\/wp-json\/wp\/v2\/doc_tag?post=1888"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}