Home Forums Backend Issues (wp-admin) Get post language in acf/save_post


Get post language in acf/save_post

  • Hi!

    I have a custom listener that renames a post based on the contents of a couple of acf fields.

    // Set name and slug based on week number and product
    function mk_weekmenu_post_type_update($post_id) {
    	if (get_post_type($post_id) == 'weekmenu') {
    		$week = get_field('menu_week');
    		$product = get_field('product');
    		$menuName = sprintf(__('%s v. %s', 'mk'), $product->post_title, $week);
    		$deliveryDate = DateTime::createFromFormat('Ymd', get_field('menu_delivery'));
    			'ID' => $post_id,
    			'post_title' => $menuName,
    			// Slug
    			'post_name' => sanitize_title($product->post_title . ' ' . $deliveryDate->format('Y') . ' v.' . $week)
    add_action('acf/save_post', 'mk_weekmenu_post_type_update', 20);

    This works well, but my problem is that since i’m getting a translation with __(‘%s v. %s’, ‘mk’) ACF is basing this on the admin language set for the user.

    If I set the checkbox “Set admin language as editing language.”
    Then the right translation is used when I save the post.

    But if it’s unchecked I always get my default language.

    How can I get the language of the post being saved and use that for the __() translation? so that the administrators language doesn’t matter

  • Hi @leon

    I’m not sure I understand the issue. Could you please share the input and the result when you enabled and disabled the “Set admin language as editing language.”?

    Also, I believe that options are related to WPML. Could you please get in touch with their support too?

    Thanks 🙂

Viewing 2 posts - 1 through 2 (of 2 total)

The topic ‘Get post language in acf/save_post’ is closed to new replies.