Hi ,
continue to the earlier ticket I raised https://toolset.com/forums/topic/custom-type-custom-permalinks-doesnt-work-as-expected/?bbp_reply_to=1682963&_wpnonce=b5d5ed1f05#new-post
It still not working. I installed "Custom Post Type Permalinks" and "Simple Post Type Permalinks", it still doesn't change the permalinks. Now the permalink always starts with "CRED Auto Draft" + random character. How can I change to just simple post id?
Hello, it looks like you have a Form that creates custom posts. You want to set the post title, post slug, and post permalink format automatically to be the post ID. I can help you set that up. You can use this custom code snippet:
add_action('cred_save_data','tssupp_set_post_id_as_title_and_slug',10,2);
function tssupp_set_post_id_as_title_and_slug($post_id,$form_data) {
if ($form_data['id']==1234) {
$args = array('ID' => $post_id, 'post_title' => $post_id, 'post_name' => $post_id);
wp_update_post($args);
}
}
Replace 1234 with the numeric ID of this Form. That is the only change you should make in the code. Then save the code in your child theme's functions.php file, or create a new custom code snippet in Toolset > Settings > Custom Code.
This will set the post title and post slug to be the numeric ID of the post. The default permalink format will be https://yoursite.com/post-type-slug/{post-id}/
Let me know if I misunderstood what you want to accomplish.
Thanks a lot. I spent more than 2 days to figure out this problem, I tried many methods and it still not working.
The permalink is almost perfect, it just has a litter problem. the link format is hidden link
Why does it has question mark and equal mark? And my-type comes with the id, not seperated by /
Okay so the title and slug are saved correctly, but the permalink structure is defaulting to a query string instead of pretty permalinks. It sounds like a problem in the permalinks formatting, or maybe pretty permalinks are turned off? I'm not sure. I would try to resave permalinks in wp-admin > Settings > Permalinks. Then I would go to Toolset > Post Types and edit this post type. In Options, check Rewrite, it should be turned ON. Please take several screenshots of the Options panel so I can see the other options. I will review your settings and give you some feedback.
I did try resave wp-admin > Settings > Permalinks to plain, and tick rewrite. it still the same.
Okay yes, if you set the Permalinks structure to "Plain", then the URLs will use the "ugly" permalinks format https://yoursite.com/?my-type=12345 instead of "pretty" permalinks. If you want to use the pretty permalink structure https://yoursite.com/my-type/post-slug, you must choose one of the other options in Permalink settings like Day and Name, Month and Name, or Post Name. Sorry for the confusion, I assumed you were aware of the difference between "Ugly" and "Pretty" permalinks but I should have been more clear about the difference: https://wordpress.org/support/article/using-permalinks/
I understand I choose the plain structure. But there isn't a structure of hidden link, even in custom structure I don't see this option.
But there isn't a structure of hidden link, even in custom structure I don't see this option.
Yes that is correct. The post ID is not offered in any of the options provided by WordPress. So in conclusion:
- Choose one of the "pretty" permalink options. The option you choose will be used to apply "pretty" permalinks to the standard WordPress Posts. It will not change the structure of permalinks for custom post types, but it will activate pretty permalinks.
- Use the custom code we have already discussed to apply the post ID to the post title and post slug of your custom post type
- The custom post type permalink structure will now show up in the URL as yoursite.com/my-type/post-id
My issue is resolved now. You are better than the supporter of my last ticket. you have clearly explained the logic behind. Thank you!
Here is the summary for myself.
1. click any option other than Plain in Settings -> Permalinks. I choose Custom Structure, enter /%post_id%/ in the followed textbox.
2. copy your code, change the form id. Form id can be found in Toolset -> post forms
3. in Toolset -> post types -> edit, tick Rewrite, choose "Use the normal WordPress URL logic".
4. if you want to have a custom URL, it can tick "Use a custom URL format". you can use any tag format in Settings -> Permalinks -> Custom Structure