Skip Navigation

[Gelöst] custom title for post relationship item

This support ticket is created vor 5 Jahren, 11 Monaten. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Heute stehen keine Supporter zur Arbeit im Werkzeugsatz-Forum zur Verfügung. Sie können gern Tickets erstellen, die wir bearbeiten werden, sobald wir online sind. Vielen Dank für Ihr Verständnis.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Karachi (GMT+05:00)

Dieses Thema enthält 29 Antworten, hat 2 Stimmen.

Zuletzt aktualisiert von Akhil vor 5 Jahren, 10 Monaten.

Assistiert von: Waqar.

Author
Artikel
#1175357

Hi Dee,

Thanks for sharing the updated username and I was able to log in to the admin area.

An important point to note is that an intermediary post is created only in the result of a "many-to-many" relationship, which means that a title can also be set only for a many-to-many relationship/connections.
( ref: https://toolset.com/documentation/post-relationships/how-to-set-up-post-relationships-using-toolset/ )

On your website, I only see "1" many-to-many relationship ("Current Tenants [P] in Industrials"), which is why what have we been discussing in this thread would actually only apply to this one intermediary post type.

I hope this clarifies and I apologize as I feel I should've thought about this point earlier.

regards,
Waqar

#1175359

Thanks but im still not clear anyway is there any workaround for this ?
changing my post relationship type etc ?

could you also let me know how to fetch the taxonomy value in the custom post title as discussed previously. thank you .

#1175360

Hi,
im still havent fully study or apply the PR .
i am guessing my initial approach is already wrong, most of it should be many-to-many PR type. whats your view pls.

#1175370

Hi Dee,

Thanks for writing back.

If it is an absolute requirement that each post-relationship item should exist as an entity of its own, (which can have a title and custom fields etc) then you'll need to have it as part of an intermediary post type, which means that the relationship should be of type "Many-to-Many".

If you'll decide you'll need to change certain relationships to many-to-many, then it would be best to delete the existing ones and create them as new ones. I'm suggesting this because when the type of existing relationship is changed, its posts associations are lost anyway and I also noticed that your website's relationships are older migrated relationships.

As for getting the taxonomy title for generating the automatic post title, you can use the "wpv-post-taxonomy" shortcode.
( ref: https://toolset.com/documentation/user-guides/views-shortcodes/#vf-153472 )

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' ) {

		$post_id = $postarr['ID'];
 
		// Process title value as needed
		$title = do_shortcode('[wpv-post-taxonomy id="'.$post_id.'" type="taxonomy-slug" separator="-" format="name" order="asc"]');
 
		$data['post_title'] =  $title ; //Updates the post title to your new title.
	}
	return $data; // Returns the modified data.
}

regards,
Waqar

#1175371

Yes its old migrated , i guess i should delete and re-create them .
i'll study and test the kind of post relationship that suitable for my case, ill update soon .

Thank You Waqar,

#1175381

That sounds like a good plan, Dee.

Since the actual issue concerning this thread seems to be sorted out, I'll recommend marking this one as resolved.

You're welcome to open a new one, in case you have any further question, related to post relationships, to avoid clutter.

regards,
Waqar

#1181510

Hi waqar, so for delay

i have this code currently

$field_1 = $postarr['wpcf']['property-type'];

whats the exact replacement for taxonomy ?
is this this below?

$field_1 = $postarr[wpv-post-taxonomy id="'.$post_id.'" type="property-type" separator="-" format="name" order="asc"];

#1182055

Hi Dee,

Thanks for writing back.

I'm afraid, there is no exact replacement similar to "$postarr['wpcf']" in case of intermediary post types and taxonomies because they are more complex than simple post types.

The simple custom post types can be created or edited through their own edit screen, but the intermediary posts can be generated and edited from the related post edit screens too.

If you could share specific details around intermediary post and taxonomy title that you're referring to from your website, I'll be in better position to guide you accordingly.

Note: Please share updated username and password for the admin area and your next reply is set as private.

regards,
Waqar

#1183367

Hi Waqar, good day ..

The custom title is not for inter post, normal custom post type. thank you .

here's my not working snippets.

add_filter( 'wp_insert_post_data' , 'modify_post_title_house' , '99', 2 );

function modify_post_title_house( $data, $postarr ) {
//$post_id = $postarr['ID'];
if($data['post_type'] == 'house' && isset($postarr['wpcf']) )
{
//for sale : Bungalow
$field_1 = $postarr['wpcf']['property-type'];
// $field_2 = do_shortcode('[wpv-post-taxonomy id="'.$post_id.'" type="house-types" separator="-" format="name" order="asc"]');
// $field_2 = $postarr['wpv-post-taxonomy id="'.$post_id.'" type="house-types" separator="-" format="name" order="asc" '];

$title = '';
if(isset($field_1) && $field_1 != '') // property type
$title .= $field_1 . ' : ';

if(isset($field_2) && $field_2 != '') //house -type tax
$title .= $field_2 . ' ';

$data['post_title'] = $title ;
//Updates the post title to your new title.
}
return $data;
// Returns the modified data.
}

#1183606

Hi Dee,

For a regular custom post type, you can use the code from the following example, to see how to get the values of taxonomy terms from the "$postarr" array:


add_filter( 'wp_insert_post_data' , 'modify_post_title_house' , '99', 2 );

function modify_post_title_house( $data, $postarr ) {

	if($data['post_type'] == 'house' && isset($postarr['wpcf']) )
	{
		$tax_slug = "house-types";
		if(count($postarr['tax_input'][$tax_slug]) >= 2)
		{
			$title = '';
			for ($i=1; $i < count($postarr['tax_input'][$tax_slug]) ; $i++) {
				$term = get_term( $postarr['tax_input'][$tax_slug][$i], $tax_slug );
				$term_name = $term->name;
				$title .= '-'.$term_name;
			}
				
			$data['post_title'] = ltrim($title,"-");
		}
	}
	return $data;
	// Returns the modified data.
}

The above example gets term IDs for the attached taxonomy terms "house-types" for the post and use their names to form a title, separated by "-".

regards,
Waqar

#1183610

Thanks Waqar !

wow !! it does look very complicated to me ,
could you mark the next reply private, i would like to share the exact code that really need your help modify.
i have 10 other cpt , i will study from this sample and modify the rest

many thanks !

#1184245

Hi Dee,

Thanks for the update and I apologize for the delay.

Getting the value of attached taxonomy terms is slightly more complicated than the custom field values because, at a time, more than one terms can be assigned to a post (hence the "for" loop).

If you'll study the last code snippet it gets the attached term names for a specified taxonomy (house-types), separated by "-". You can extend it to include other custom fields and taxonomy terms as needed.

As much as we would like to help, 1-1 custom code assistance and its troubleshooting are beyond the scope of support that we provide ( https://toolset.com/toolset-support-policy/ ), but we do our best to guide in the right direction, whenever possible.

If you feel that a specific customization requirement is becoming too complex, you can consider hiring a professional from our list of recommended contractors:
https://toolset.com/contractors/

Please let me know if any code example or point from this thread is not clear. For different question or concern, you're welcome to start a new ticket.

regards,
Waqar

#1184873

Hi Wafar,thanks for the follow up.

the code was helpful , i managed to get what i wanted the custom post title.

As usual my concern is a the performance issue. i don't really need help with the code for now, but advice on the toolset performance will be most appreciated.

Previously i had the categories as custom field. Then after considerations ive ported into taxonomies. which is working great, Now , custom title is equally important , but if its going to be a performance issue then ill just have to duplicate the tax into custom field.

regarding your concern " tax is going to be used at other cpt " , not for this case as this tax is for 1 cpt for better management purpose.

Next topic , i will be looking at ways to sync the tax and duplicated custom field. example.
Tax property type : for sale. to be copied to custom field property type :for sale etc. Is this even possible ?

Thanks

#1185677

Hi Dee,

Thanks for writing back and glad you managed to get the code working.

If you're planning to duplicate store the assigned taxonomy terms as custom field values and then using that for generating title, in order to increase performance, I wouldn't recommend that. This would be adding more processing and hence would reduce performance.

Here is an overview:

Current approach:

Get the taxonomy terms -> Use them to generate title

Planned approach:

Get the taxonomy terms -> Store them into a custom field -> Use that custom field value to generate title

So my point is, that if taxonomy terms are involved, it is not possible to skip the step of getting their values ( ref: https://toolset.com/forums/topic/custom-title-for-post-relationship-item/page/2/#post-1183606 ). So I don't see any benefit of storing their duplicate as a custom field value (on the contrary this will add more processing).

I hope this makes sense and let me know If I'm missing something.

regards,
Waqar

#1185686

My issue is resolved now. Thank you!

could you help me look at this ticket too :https://toolset.com/forums/topic/custom-title-for-post-part-2/#post-1185689

thanks