This site is running Voxel Theme Version: 1.7.5.2 | Elementor Plugin Version: 3.35.5

Join the Voxel Guide Community!

Get Involved

Create Post (VX) - Redirect after Submission

Description/Instructions

I used Gemini AI to help me with this little snippet.

If anyone finds fault in this code, please please let me know. But for me, it works!

The setup:
– User creates a post
– In my case, the post is set to ‘Pending Review’
– The redirect url to the post created is the edit post url structure.

I’m sure there’s a more elegant way, but this works for me.

NOTE: I was using the Essential Add-ons for Voxel, but have found this plugin extremely buggy and unreliable.

Thanks.

Instructions

Give your Create Post (VX) widget an ID name. In my example it is 'create-location'.

Add the code below in an HTML code widget below the Create Post (VX) widget.

Change:
const finalUrl = `${baseUrl}/?post_type=YOUR_POST_TYPE_HERE&p=${newPostId}`;

<script>
(function() {
const targetNode = document.getElementById('create-location');
if (!targetNode) return;

const config = { childList: true, subtree: true };

const callback = function(mutationsList, observer) {
for (const mutation of mutationsList) {
if (mutation.type === 'childList') {
// Detecting the Voxel success message
if (targetNode.innerText.includes("Your post has been submitted for review")) {

const links = targetNode.querySelectorAll('a');
let newPostId = null;

// Extracting the ID from the "Back to editing" button link
links.forEach(link => {
const href = link.getAttribute('href');
const match = href.match(/(?:post_id=|posts\/)(\d+)/);
if (match && match[1]) {
newPostId = match[1];
}
});

observer.disconnect();

if (newPostId) {
// Uses the current domain automatically
const baseUrl = window.location.origin;
const finalUrl = `${baseUrl}/?post_type=location-directory&p=${newPostId}`;

window.location.href = finalUrl;
} else {
// Fallback to the current page/home if ID is missed
window.location.href = '/';
}
}
}
}
};

const observer = new MutationObserver(callback);
observer.observe(targetNode, config);
})();
</script>

  • HTML
Copy Code

Let's Chat About this Snippet

Chat Toggle
Voxel Guide AI
Voxel Guide AI
Voxel Guide AI
Voxel Guide AI
Ask me anything about Voxel!
Send
Powered by AI24