Auto-set a term’s language when created in wp admin
-
I’m using the free version of polylang; and I’m trying to find a way for the following:
Let’s say you’re either on the page to create a post in the wp admin, or on the one to edit an existing one. On that page, you go to the tags metabox on the right post properties configs. Now you enter a new tag name and hit enter. WP then creates the tag and adds it via REST API. So far so good. Problem: the created term has no language, and what if you set that taxonomy to be language – specific?
To make taxonomy pages work, the language of the according terms have to be set appropriately, from what I’ve learned and tried. Hence, I’m trying to auto-set the language of a term, right when it’s created. I was able to do this via:
add_action( 'create_post_tag', function( $term_id ) { if ( ! function_exists( 'pll_set_term_language' ) ) { require_once WP_CONTENT_DIR.'plugins/polylang/include/api.php'; } pll_set_term_language( $term_id, 'de' ); } );
Like this, my terms however always get the language GERMAN assigned; so I need to figure out the missing piece of code to set the language equal to the one which is currently applied to the post in the create / edit post admin page (I only need to enable this feature on these two pages). How can I do this?
- The topic ‘Auto-set a term’s language when created in wp admin’ is closed to new replies.