• Hello,

    I have a dev question: I would like to use get_post_type_archive_link() function in back-end. I noticed that its return value is not filtered by Polylang and thus it lacks language code.

    I find out that link filters are activated only on front-end and I guess that they won’t work right out of the box on back-end, because they rely on current language and “current language” in back-end seems to be whatever is the value of language filter, so there is no actual current language when “Show all languages” item is selected.

    My intention is to display post type archive link with current language of the back-end user – is there an easy way to do it with Polylang? Or should I rather try to implement it on my own? I know I can get current back-end user language via get_locale(), but I would like to reuse link filters from Polylang as much as possible.

    I’m working with Polylang 1.8.1 and WordPress 4.4.1.

    Greetings,
    Česlav

    https://wordpress.org/plugins/polylang/

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

    (@chouby)

    Hi!

    Yes post type archives links are filtered only on frontend. The filter is done in frontend/frontend-filters-links.php. I would rather not try to instantiate the whole PLL_Frontend_Filters_Links class on admin side as I would expect strange results with other functions. The easiest would be to copy only the filter you are interested in. Only one line of code 😉

    function post_type_archive_link( $link, $post_type ) {
    	return pll_is_translated_post_type( $post_type ) ? PLL()->links_model->add_language_to_link( $link, PLL()->curlang ) : $link;
    }
    Thread Starter Česlav Przywara

    (@chesio)

    Thanks Chouby,

    Your snippet does the trick, though I had to use PLL()->pref_lang instead of PLL()->curlang, because the latter expression returns false whenever the language filter is set to “Show all languages” (as I mentioned above).

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Front-end filters for links available also on back-end?’ is closed to new replies.