• Resolved Teemu Suoranta

    (@teemusuoranta)


    Hi!

    I was wondering if there was a way to find out the language of a post in post-new.php that hasn’t been saved and thus has no ID. At this point global $post object has no ID (and is in fact null). This is problematic because the Polylang functions that return the current language require this ID.

    In theory, an automatic draft is created as soon as post-new.php is opened but to my knowledge there is no way to get the ID of this auto-draft.

    Is there some function I am missing or is this just not possible? I need the language in PHP as I’m building some logic that would need the current language. In existing post I could easily just get the ID of the post and get language from there.

    https://www.ads-software.com/plugins/polylang/

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Author Chouby

    (@chouby)

    Hi Teemu,

    The default language assigned to a new post is stored in PLL()->pref_lang. It can be filtered with ‘pll_admin_preferred_language’.

    Plugin Author Chouby

    (@chouby)

    Hi Teemu,

    The default language assigned to a new post is stored in PLL()->pref_lang. It can be filtered with ‘pll_admin_preferred_language’.

    Plugin Author Chouby

    (@chouby)

    Hi Teemu,

    The default language assigned to a new post is stored in PLL()->pref_lang. It can be filtered with ‘pll_admin_preferred_language’.

    Plugin Author Chouby

    (@chouby)

    Hi Teemu,

    The default language assigned to a new post is stored in PLL()->pref_lang. It can be filtered with ‘pll_admin_preferred_language’.

    Thread Starter Teemu Suoranta

    (@teemusuoranta)

    Hi!

    This is great news! Got it working. Here’s a bullet-proof way of getting post language in edit screen:

    1. Check for $_GET[‘new_lang’]
    2. Check for post id
    3. No post id? Check for PLL()->pref_lang

    I might make a Gist snippet for this. This could be a nice function for Polylang, too. I could call it pll_current_admin_post_language() or something more catchy.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Find out current language in post-new.php’ is closed to new replies.