{"id":2926,"date":"2026-10-20T08:39:21","date_gmt":"2026-10-20T07:39:21","guid":{"rendered":"https:\/\/wpgeodirectory.com\/documentation\/article\/get-custom-field-value-in-php-2\/"},"modified":"2026-10-20T08:39:21","modified_gmt":"2026-10-20T07:39:21","slug":"get-custom-field-value-in-php-2","status":"publish","type":"gd_place","link":"https:\/\/wpgeodirectory.com\/documentation\/article\/code-snippets\/get-custom-field-value-in-php-2\/","title":{"rendered":"How to get a custom field value in PHP"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">GeoDirectory stores custom field values in its own table for each post type, not in WordPress post meta, so <code>get_post_meta()<\/code> returns nothing for them. Use <code>geodir_get_post_meta()<\/code> with the listing ID and the field key:<\/p>\n\n\n\n<pre class=\"wp-block-prismatic-blocks\"><code class=\"language-php\">$instagram = geodir_get_post_meta( $post_id, &#039;instagram&#039;, true );<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The key is the Key setting of the field in Places &gt; Settings &gt; Custom Fields. In GeoDirectory v1 custom field keys started with <code>geodir_<\/code>, for example <code>geodir_instagram<\/code>. The upgrade to v2 removed that prefix, so use the key exactly as the field settings show it.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Get all fields of a listing at once<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\"><code>geodir_get_post_info()<\/code> returns an object with every field of the listing, which is handy when you need several values:<\/p>\n\n\n\n<pre class=\"wp-block-prismatic-blocks\"><code class=\"language-php\">$listing = geodir_get_post_info( $post_id );\n\nif ( ! empty( $listing-&gt;instagram ) ) {\n\techo esc_html( $listing-&gt;instagram );\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">On a listing detail page and inside GeoDirectory loops, the global <code>$gd_post<\/code> already holds that object for the current listing:<\/p>\n\n\n\n<pre class=\"wp-block-prismatic-blocks\"><code class=\"language-php\">global $gd_post;\n\nif ( ! empty( $gd_post-&gt;instagram ) ) {\n\techo esc_html( $gd_post-&gt;instagram );\n}<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Showing a value without code<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">If you only want to display the value on a page, the GD &gt; Post Meta block does it without PHP. Show set to &#8220;value (saved in database)&#8221; outputs the raw stored value:<\/p>\n\n\n\n<pre class=\"wp-block-prismatic-blocks\"><code class=\"language-markup\">&#091;gd_post_meta key=&#039;instagram&#039; show=&#039;value-raw&#039;&#093;<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">See <a href=\"https:\/\/wpgeodirectory.com\/documentation\/article\/how-tos\/how-can-i-display-a-custom-field-database-value\/\">How can I display a custom field database value?<\/a> for more on that.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>GeoDirectory stores custom field values in its own table for each post type, not in WordPress post meta, so get_post_meta() returns nothing for them. Use geodir_get_post_meta() with the listing ID and the field key: The key is the Key setting of the field in Places &gt; Settings &gt; Custom Fields. In GeoDirectory v1 custom field [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"","ping_status":"closed","template":"","meta":{"footnotes":""},"article\/tags":[],"article\/categories":[211,433],"class_list":["post-2926","gd_place","type-gd_place","status-publish","hentry","gd_placecategory-tips-tricks-more","gd_placecategory-code-snippets"],"_links":{"self":[{"href":"https:\/\/wpgeodirectory.com\/documentation\/wp-json\/wp\/v2\/article\/2926","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wpgeodirectory.com\/documentation\/wp-json\/wp\/v2\/article"}],"about":[{"href":"https:\/\/wpgeodirectory.com\/documentation\/wp-json\/wp\/v2\/types\/gd_place"}],"author":[{"embeddable":true,"href":"https:\/\/wpgeodirectory.com\/documentation\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/wpgeodirectory.com\/documentation\/wp-json\/wp\/v2\/comments?post=2926"}],"version-history":[{"count":0,"href":"https:\/\/wpgeodirectory.com\/documentation\/wp-json\/wp\/v2\/article\/2926\/revisions"}],"wp:attachment":[{"href":"https:\/\/wpgeodirectory.com\/documentation\/wp-json\/wp\/v2\/media?parent=2926"}],"wp:term":[{"taxonomy":"gd_place_tags","embeddable":true,"href":"https:\/\/wpgeodirectory.com\/documentation\/wp-json\/wp\/v2\/article\/tags?post=2926"},{"taxonomy":"gd_placecategory","embeddable":true,"href":"https:\/\/wpgeodirectory.com\/documentation\/wp-json\/wp\/v2\/article\/categories?post=2926"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}