I am trying to:
We use a form for our customers to create custom posts of a particular CPT. We've always used the default Toolset generated URL for these posts because it's unique and doesn't require anything of the user submitting it.
Seemingly out of nowhere today the URLs stopped being unique.
Every post created with the form has a URL ending in cred-auto-draft-c8753e0c5d38195974c3942235a490d3
...so for instance the last three posts created are all linked to:
website.com/cpt/cred-auto-draft-c8753e0c5d38195974c3942235a490d3
website.com/cpt/cred-auto-draft-c8753e0c5d38195974c3942235a490d3
website.com/cpt/cred-auto-draft-c8753e0c5d38195974c3942235a490d3
Link to a page where the issue can be seen:
This is a stripped down version of the same form. No JS...
You can fill out the form and you will be redirected to a url ending in cred-auto-draft-c8753e0c5d38195974c3942235a490d3
You can fill it out again and will again be redirected to the same cred-auto-draft-c8753e0c5d38195974c3942235a490d3 url
enlace oculto
On the backend of the site, if you click the view link under each post you will be taken to this same URL everytime. The information in the post will be unique, but the URL will not be.
I expected to see:
A unique URL
Instead, I got:
website.com/cpt/cred-auto-draft-c8753e0c5d38195974c3942235a490d3
A few things to NOTE
1) This is happening on four instances of the same site: Live, staging, test, dev...
all of these sites have varying degrees of plugin/theme/wp versions. The version I'm sharing is the most up-to-date in every regard.
2) We will look into changing the permalink structure following this so we're not relying on Toolset Forms to generate unique URLs, however, we want to be very sure this isn't a larger problem with greater implications.
3) I have a php script that I've been using for over a year without issue that renames posts using Toolset Custom Field data. This is included in Toolset Custom Code under settings and has not been showing any errors. Again, it's been in use for quite sometime.
However, on the dev site I turned it off and started getting different results with the URLs (-1, -2, -3 appended)...
website.com/cpt/cred-auto-draft-c8753e0c5d38195974c3942235a490d3-1
website.com/cpt/cred-auto-draft-c8753e0c5d38195974c3942235a490d3-2
website.com/cpt/cred-auto-draft-c8753e0c5d38195974c3942235a490d3-3
For the test instance of the site, I have left this on. Here is the code...
<?php
/**
* New custom code snippet (replace this with snippet description).
*/
toolset_snippet_security_check() or die( 'Direct access is not allowed' );
// Put the code of your snippet below this comment.
add_action("cred_save_data", "customsub_save_data_action",10,2);
function customsub_save_data_action($post_id, $form_data)
{
// if a specific form
if ($form_data["id"]==435)
{
$subseries = $_POST["wpcf-mainsub-series-opt"];
// Update the post into the database
$name = $subseries ."-". $post_id;
$customsub_post = array(
'ID' => $post_id,
'post_title' => $name,
'post_name' => $name
);
wp_update_post( $customsub_post );
}
if ($form_data["id"]==436)
{
$subseries = $_POST["wpcf-mainsub-series-opt"];
// Update the post into the database
$name = $subseries ."-". $post_id;
$customsub_post = array(
'ID' => $post_id,
'post_title' => $name,
'post_name' => $name
);
wp_update_post( $customsub_post );
}
}