Skip Navigation

[Resolved] Sync Categories and Tags conditionally in Types

This support ticket is created 3 years, 5 months ago. 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.

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

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/Hong_Kong (GMT+08:00)

Tagged: 

This topic contains 1 reply, has 2 voices.

Last updated by Luo Yang 3 years, 5 months ago.

Assisted by: Luo Yang.

Author
Posts
#1831037

Hi,

I should have to sync a website's Categories and Tags according to this:
1) User assigns tags to a post being created on frontend (with 3rd party form) and saves it.
2) I'd like Toolset (Types) to assign SOME of these Tags as Categories automatically to the post created,
according to this:
IF term meta of Tags default WP taxonomy named "Is Brand (slug: is-brand, key: ?is_brand?) is TRUE,
then assign this (only these) Tag as Category to this Post

That would be great to be able to do such syncs in Types!

I found, modified and tried this PHP function but it doesn't work:

function assign_categories_based_on_brand_tags( $post_id ) {
    $args = array( 'fields' => 'name' );
    $tags = wp_get_post_tags( $post_id, $args );
    $tag_names = implode( ', ', $tags );
    $is_brand = wp_get_term_meta( $term_id, $key = 'is_brand' );
    if ( $is_brand ) {
		wp_set_post_categories( $post_id, $tag_names, true );
	}
}

but this doesn't work 🙁

Thank you!

#1831751

Hello,

You need to trigger you custom PHP function with some action hook, for example WP built-in action hook save_post, see WP document:
https://developer.wordpress.org/reference/hooks/save_post/
Fires once a post has been saved.

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.