• Resolved Salih K

    (@salihkulangara)


    I have a custom post type and custom taxonomy bound to that CPT, I need to add some extra data to taxonomy terms, So I can do this using “update_term_meta” but this only work if I am adding the terms/categories through Edit Taxonomy screen, but how can we update the custom term_meta while adding through “Add New <<tax term>” in the post editor UI while adding new post? Is this possible?

Viewing 6 replies - 1 through 6 (of 6 total)
  • Moderator bcworkz

    (@bcworkz)

    You could use "create_{$taxonomy}" or "edit_{$taxonomy}" actions to do something when a term in $taxonomy is added or updated. Where is the data for term meta coming from? Will it always be available when a new term is added through the post editor’s meta box? If the term meta data is dependent upon post data of some sort which may not always be available until the post is saved, you could use the 'save_post' action to add term meta. The problem here is we wouldn’t know which term was added and which already existed.

    Thread Starter Salih K

    (@salihkulangara)

    I have created the term meta using the hooks, that works for me when we are adding/editing the term meta from the taxonomy edit page. I was asking when we add through post edit page taxonomy UI, is there any possibility to update term meta. As you said I also see a least chance for this, but just asking the community if any workaround or tips that we can use.

    The feature I am looking for is I dont want to go to the other screen and add a term meta for the new term I add for a new post I am creating, when I save post I need to update term meta for the one I just created(may be a default value) right away. ??

    • This reply was modified 4 years, 3 months ago by Salih K.
    • This reply was modified 4 years, 3 months ago by Salih K.
    Moderator bcworkz

    (@bcworkz)

    When we add a new term through the post edit screen’s meta box, the "create_{$taxonomy}" should still fire. Any callback added to that hook should still work.

    Thread Starter Salih K

    (@salihkulangara)

    For some reason I dont see it is working for me, I will check in detail.
    Thank you.

    Moderator bcworkz

    (@bcworkz)

    You’re welcome. I double checked using my taxonomy “genre” with this:

    add_action('create_genre', function( $x ) {
    	error_log("New genre term created with ID $x");
    });

    An entry is logged from the post edit screen when using this code. I’m using the default block editor to test.

    Thread Starter Salih K

    (@salihkulangara)

    Now I am able make it work, thank you so much.

    • This reply was modified 4 years, 3 months ago by Salih K.
Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘How to add term_meta while adding term using post editor UI?’ is closed to new replies.