{"id":2530,"date":"2026-10-20T08:34:13","date_gmt":"2026-10-20T07:34:13","guid":{"rendered":"https:\/\/wpgeodirectory.com\/documentation\/article\/object-of-class-wp-post-could-not-be-converted-to-int\/"},"modified":"2026-10-20T08:41:01","modified_gmt":"2026-10-20T07:41:01","slug":"object-of-class-wp-post-could-not-be-converted-to-int","status":"publish","type":"gd_place","link":"https:\/\/wpgeodirectory.com\/documentation\/article\/troubleshooting\/object-of-class-wp-post-could-not-be-converted-to-int\/","title":{"rendered":"PHP notice: Object of class WP_Post could not be converted to int"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">This notice means some code passed a whole post object to a function that expects a post ID number. It is a coding mistake in a theme, child theme or snippet, and the fix is to pass <code>$post-&gt;ID<\/code> instead of <code>$post<\/code>. It is only a notice and the page still loads, but hiding it leaves the bug in place.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Find where it comes from<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">The notice in your debug log names a file and line. If that file is in your theme or a snippet, look at the function call on that line and check what it is given. A common case in GeoDirectory customisations is the favourite button:<\/p>\n\n\n\n<pre class=\"wp-block-prismatic-blocks\"><code class=\"language-php\">\/\/ Wrong: passes the post object.\necho geodir_favourite_html( get_current_user_id(), $post );\n\n\/\/ Right: passes the post ID.\necho geodir_favourite_html( get_current_user_id(), $post-&gt;ID );<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">If the file is inside the GeoDirectory plugin, look further down the stack trace for the first file from your theme or snippets. That is usually where the wrong value started.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Use the shortcode instead of plugin functions<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">In custom templates it is safer to output GeoDirectory elements with their shortcodes, because shortcode options stay stable when internal functions change. For the favourite button:<\/p>\n\n\n\n<pre class=\"wp-block-prismatic-blocks\"><code class=\"language-php\">echo do_shortcode( &#039;&#091;gd_post_fav&#093;&#039; );<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">It picks up the current listing on its own. The options are in <a href=\"https:\/\/wpgeodirectory.com\/documentation\/article\/core-widgets\/gd-post-favorite\/\">GD &gt; Post Favorite<\/a>. Every other element can be added the same way with the shortcode builder.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Hide notices on a live site<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Notices should never be shown to visitors. In <code>wp-config.php<\/code>, keep logging on and display off while you fix the cause:<\/p>\n\n\n\n<pre class=\"wp-block-prismatic-blocks\"><code class=\"language-php\">define( &#039;WP_DEBUG&#039;, true );\ndefine( &#039;WP_DEBUG_LOG&#039;, true );\ndefine( &#039;WP_DEBUG_DISPLAY&#039;, false );<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>This notice means some code passed a whole post object to a function that expects a post ID number. It is a coding mistake in a theme, child theme or snippet, and the fix is to pass $post-&gt;ID instead of $post. It is only a notice and the page still loads, but hiding it leaves [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"article\/tags":[],"article\/categories":[211,437],"class_list":["post-2530","gd_place","type-gd_place","status-publish","hentry","gd_placecategory-tips-tricks-more","gd_placecategory-troubleshooting"],"_links":{"self":[{"href":"https:\/\/wpgeodirectory.com\/documentation\/wp-json\/wp\/v2\/article\/2530","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=2530"}],"version-history":[{"count":1,"href":"https:\/\/wpgeodirectory.com\/documentation\/wp-json\/wp\/v2\/article\/2530\/revisions"}],"predecessor-version":[{"id":2708,"href":"https:\/\/wpgeodirectory.com\/documentation\/wp-json\/wp\/v2\/article\/2530\/revisions\/2708"}],"wp:attachment":[{"href":"https:\/\/wpgeodirectory.com\/documentation\/wp-json\/wp\/v2\/media?parent=2530"}],"wp:term":[{"taxonomy":"gd_place_tags","embeddable":true,"href":"https:\/\/wpgeodirectory.com\/documentation\/wp-json\/wp\/v2\/article\/tags?post=2530"},{"taxonomy":"gd_placecategory","embeddable":true,"href":"https:\/\/wpgeodirectory.com\/documentation\/wp-json\/wp\/v2\/article\/categories?post=2530"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}