{"id":2346,"date":"2026-10-20T08:32:18","date_gmt":"2026-10-20T07:32:18","guid":{"rendered":"https:\/\/wpgeodirectory.com\/documentation\/article\/redirect-after-submit-listing\/"},"modified":"2026-10-20T08:39:57","modified_gmt":"2026-10-20T07:39:57","slug":"redirect-after-submit-listing","status":"publish","type":"gd_place","link":"https:\/\/wpgeodirectory.com\/documentation\/article\/code-snippets\/redirect-after-submit-listing\/","title":{"rendered":"How to redirect users to another page after they submit a listing"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">After a listing is submitted, GeoDirectory stays on the Add Listing page and shows a message with a link to view or preview the listing. There&#8217;s no setting to change this, but a short snippet can send the user to any page you choose.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">The snippet<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Add this with the <a href=\"https:\/\/wpgeodirectory.com\/documentation\/article\/useful-plugins\/code-snippets-plugin\/\">Code Snippets plugin<\/a> or in your child theme&#8217;s functions.php, and change the URL:<\/p>\n\n\n\n<pre class=\"wp-block-prismatic-blocks\"><code class=\"language-php\">\/**\n * Redirect to a page after the GeoDirectory add listing form is submitted.\n *\/\nfunction my_gd_redirect_after_submit( $message, $post_data ) {\n\t\/\/ Only redirect new listings, not edits of existing ones.\n\tif ( ! empty( $post_data&#091;&#039;post_parent&#039;&#093; ) ) {\n\t\treturn $message;\n\t}\n\n\t$redirect_to = home_url( &#039;\/thank-you\/&#039; ); \/\/ Change this.\n\n\t$message .= &#039;&lt;script&gt;window.location.href = &#039; . wp_json_encode( $redirect_to ) . &#039;;&lt;\/script&gt;&#039;;\n\n\treturn $message;\n}\nadd_filter( &#039;geodir_ajax_save_post_message&#039;, &#039;my_gd_redirect_after_submit&#039;, 100, 2 );<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">How it works<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">The form is saved over AJAX, and <code>geodir_ajax_save_post_message<\/code> filters the message shown afterwards. The snippet adds a small script to that message, so the browser goes to your URL as soon as the message loads.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><code>$post_data<\/code> includes the listing <code>ID<\/code> and <code>post_status<\/code>. You can use them to send people somewhere different, for example straight to their new listing with <code>get_permalink( $post_data&#091;&#039;ID&#039;&#093; )<\/code> when the status is publish. A pending listing has no public page yet, so use a thank you page for listings that need review.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Remove the <code>post_parent<\/code> check if you also want to redirect after someone edits a listing.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>After a listing is submitted, GeoDirectory stays on the Add Listing page and shows a message with a link to view or preview the listing. There&#8217;s no setting to change this, but a short snippet can send the user to any page you choose. The snippet Add this with the Code Snippets plugin or in [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"article\/tags":[],"article\/categories":[211,433],"class_list":["post-2346","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\/2346","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=2346"}],"version-history":[{"count":2,"href":"https:\/\/wpgeodirectory.com\/documentation\/wp-json\/wp\/v2\/article\/2346\/revisions"}],"predecessor-version":[{"id":2612,"href":"https:\/\/wpgeodirectory.com\/documentation\/wp-json\/wp\/v2\/article\/2346\/revisions\/2612"}],"wp:attachment":[{"href":"https:\/\/wpgeodirectory.com\/documentation\/wp-json\/wp\/v2\/media?parent=2346"}],"wp:term":[{"taxonomy":"gd_place_tags","embeddable":true,"href":"https:\/\/wpgeodirectory.com\/documentation\/wp-json\/wp\/v2\/article\/tags?post=2346"},{"taxonomy":"gd_placecategory","embeddable":true,"href":"https:\/\/wpgeodirectory.com\/documentation\/wp-json\/wp\/v2\/article\/categories?post=2346"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}