Create/update terms on wp_insert_post and wp_update_post
-
Hello!
Firstly, thanks for wonderful plugin, it helps me so much:)
I’m trying to create CPT’s posts via wp_insert_post and update post via wp_update_post() on API call from another site(that site returns ID of post which I need to update).
so all works good except of custom taxonomy terms.
I have 4 custom taxonomies but I’ll show you only 2 for example.
Now I have only 2 languages – English(default) and Russian.// $sValuesArray is demo data $sValuesArray = array('industry1', 'industry2'); $industries = wp_set_object_terms( $post_id, $sValuesArray, 'industries', true); foreach ($industries as $industry) { pll_set_term_language($industry + 1, 'ru'); } // $branchesArr is demo data $branchesArr = array('branch1','branch2'); $branches = wp_set_object_terms($post_id, $branchesArr, 'branches', true); foreach ($branches as $branch) { pll_set_term_language($branch + 1, 'ru'); }
I know that is
pll_set_term_language($branch + 1, 'ru');
– bad practice.
I do it because terms which created returns (for example) ID 1109, but in admin dashboard that ID has 1110, so for attach created russian term to ‘RU’ language I’m using this fix. Could you please provide better solution? thanks.My main trouble:
Why created terms not attaching to my post? It’s just created, but not attached.
But if I send in$branchesArr
andsValuesArray
existing terms all works good.If I disable polylang – all works good too.
Thanks for plugin and your help.
- The topic ‘Create/update terms on wp_insert_post and wp_update_post’ is closed to new replies.