Skip Navigation

[Resuelto] Automatically Add New Posts to Post Group

This support ticket is created hace 3 años, 10 meses. 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.

Hoy no hay técnicos de soporte disponibles en el foro Juego de herramientas. Siéntase libre de enviar sus tiques y les daremos trámite tan pronto como estemos disponibles en línea. Gracias por su comprensión.

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: Africa/Casablanca (GMT+01:00)

Etiquetado: 

Este tema contiene 2 respuestas, tiene 2 mensajes.

Última actualización por aaronM-9 hace 3 años, 10 meses.

Asistido por: Jamal.

Autor
Mensajes
#1898751

Is it possible to use custom code to automatically add a new post to a Toolset Access Post Group?

For details, I have a post type called "Resources" and another post type called "Events." Events are children of positions (one position can have multiple events). Each resource will be assigned to its own post group (never will it be in two post groups). When creating a new event, I would like some code that would automatically add the Event to the same post group as the Resource. Can you tell me if this is possible? Thanks in advance!

- Aaron

#1898795

Hello Aaron and thank you for contacting the Toolset support.

When a post is added to a Post Group, we save the post group in a custom field on the post. Check this similar ticket for an example https://toolset.com/forums/topic/how-to-use-cred-post-form-to-set-post-group-for-new-cpt-post/#post-572829

In order to get the Access group ID, you need to add at least one post, then you need to check the database to get the id of the post group.

But, we can't create a post group programmatically, it has to be created through the Access interface.

Let me know if you will need further help with it.

#1899649

That wasn't exactly what I was looking for but it did get me pointed in the right direction. Below please find code I ended up developing that seems to work perfectly:

add_action( 'toolset_association_created', 'croydon_assign_to_post_group', 10, 5 );

function croydon_assign_to_post_group( $association_slug, $parent_id, $child_id, $intermediary_id, $association_id ) {

	// retrieve toolset post group
	
	$post_group = get_post_meta($parent_id, '_wpcf_access_group', true);
	
	// remove pre-existing post group
	
	$toolset_remove_post_group = delete_post_meta($child_id, '_wpcf_access_group');
	
	// assign to post group
	
	if ($post_group != false) {
		
		add_post_meta($child_id, '_wpcf_access_group', $post_group);
		
	}
	
}

Thanks again for the continued support.

- Aaron