Hi.
sometime ago norman gave me workaround:https://toolset.com/forums/topic/custom-post-title-from-5-different-custom-fields/
to auto rename the post title.
i need this function for the post relationship item now. is that possible ?
thank you .
Hi Dee,
Thank you for contacting us and I'll be happy to assist.
The code that Noman suggested in his reply ( https://toolset.com/forums/topic/custom-post-title-from-5-different-custom-fields/page/2/#post-578300 ) should work for intermediary post items as well.
You'll only need to remove "&& isset($postarr['wpcf'])" part from line# 7:
For example:
add_filter( 'wp_insert_post_data' , 'modify_post_title' , '99', 2 ); // Grabs the inserted post data so you can modify it.
function modify_post_title( $data, $postarr )
{
if( $data['post_type'] == 'relationship-slug' ) {
// Process title value as needed
$title = 'Title value';
$data['post_title'] = $title ; //Updates the post title to your new title.
}
return $data; // Returns the modified data.
}
You'll replace "relationship-slug" with the actual slug of your post-relationship.
Important note: The above code will automatically update the intermediary post's title, whether it is added directly through its edit screen in the admin area or if it is generated when a relationship is created from the edit screen of the post in the relationship.
regards,
Waqar
Hi. thanks it worst but has some issue
1. the custom title doesn't change when i add new entry inside the main CPT that hold the post relationship. for my case its a many -to-many post relationship. i need to click "edit" to go into the main post relationship and click save to get the custom title.
2. also is it possible to identify the slug by many ID's instead of entering the slug., cause the slug name might change later part i am afraid.
thanks.
Hi Dee,
Thanks for sharing the update.
> 1. the custom title doesn't change when i add new entry
> inside the main CPT that hold the post relationship. for
> my case its a many -to-many post relationship. i need to
> click "edit" to go into the main post relationship and click
> save to get the custom title.
- In my tests, the functions shared in my last message worked, whether an intermediary post was added/edited through its own edit screen or if a new relationship was created from the participating child or parent post's edit screen.
If you're getting different results, please share a screenshot of exactly how you're editing the post, when the function is not executing.
> 2. also is it possible to identify the slug by many ID's instead
> of entering the slug., cause the slug name might change later
> part i am afraid.
- I assume you referring to the slug value used in the line:
if( $data['post_type'] == 'relationship-slug' ) {
If my understanding is correct, you can use "get_post_type" function ( ref: https://developer.wordpress.org/reference/functions/get_post_type/) to get the intermediary post type's slug, if you do have its ID.
But from performance points of view, this is not a good approach and it is better to manually update the slug value when or if it changes, which can't be too often.
regards,
Waqar
Hi ,
for issue one.,
pls check the screenshot.
hidden link - 1. title not updated in the cpt that contain the custom relationship.
hidden link -2. quick edit unable to update/fetch the fn
hidden link 3- only main PR edit post works,
for issue2.
thank you for sharing on the performance view. thats important.
The reason for me to use ID is i have many PR and intermediate PR to add this functions.
do you suggest to create one function for each of the PR ?
i thought of using one single function as the naming method is same for this SET of PR.
PR - post relationship
thanks.
Hi Dee,
For issue 1, I'll need access to your website's admin area, to view how the post-relationship and intermediary posts are set and why the same code is not working.
I've set your next reply as private so that only you and our support team will have access to it.
For issue 2, if you have multiple post-relationships with same custom name requirement, you can use the same function, but updating the conditional line from:
if( $data['post_type'] == 'relationship-slug' ) {
To:
if( ($data['post_type'] == 'relationship-slug') || ($data['post_type'] == 'relationship-slug-1') || ($data['post_type'] == 'relationship-slug-2') ) {
You can add even more conditions, with the "OR" sign ("||") as needed.
regards,
Waqar
Hi, Waqar
Good Day.
i realize that i am using taxonomy field too.
thus this code is not valid.
&& isset($postarr['wpcf']) )
{
$field_1 = $postarr['wpcf']['class-type'];...
could you guide me on the snippets changes for this pls, thank you.
is it wpv-post-taxonomy ?
Hi Dee,
Hope you had a good weekend and I wish you a Happy New Year.
Before moving on to your new question about the taxonomy, can you please confirm if the original issue of a function attached to "wp_insert_post_data" is fixed?
( ref: https://toolset.com/forums/topic/custom-title-for-post-relationship-item/#post-1172541 )
Does your custom code to set the title automatically works, when only custom fields and not the "taxonomy" is used?
Important point to note here is that "$postarr['wpcf']" array will hold only those values which will be available in the form to add/edit the post relationship item in question.
Without the complete picture of what specifically is not working, makes troubleshooting ineffective and totally dependant on the guess work. This results in more time than necessary for the resolution. Did you get a chance to check my message with the test email?
( screenshot: hidden link )
regards,
Waqar
Ive sent you last week, i am re-sending it now again, thanks.
the custom function is here: hidden link
pls use this post to test : hidden link
Thank You.
Hi Dee,
I've received both your emails from yesterday, but unfortunately, the login credentials are not working.
( Message: ERROR: Wrong credentials provided. Please e-mail : hello@your-domain if you need any assistance )
Can you please check the login credentials again and make sure that there are no extra server security layers involved?
In case there are some complex server security policies involved, you can also alternatively make a clone of a development website (with issue reproducible) and share it through a service like Dropbox, Google Drive etc.
We recommend "Duplicator" plugin for sharing clone/snapshot.
( https://wordpress.org/plugins/duplicator/ )
I'll wait for an update.
regards,
Waqar
Hi ive activated as i have no responce within hours, its not safe to leave it open as we have others entering data actively.
thanks for the understanding, it should be active now. pls dont install or take duplicator plugins without asking first, many thanks.
Hi Dee,
I've checked credentials again and I'm still getting the same message.
Can you please check the username and password too and make sure it works?
And of course, I won't make any change to the website, without your explicit permission.
regards,
Waqar
ok login as support_ts pls. thanks.
hi are you able to get in ?