Support » Plugin: Polylang » filtering all language front pages from query

  • Resolved RavanH


    Hi Chouby,

    Working on my XML Sitemap Feeds plugin again, I need to filter all language front pages from a loop. Currently, I’m doing it like below (creating an array of front page IDs which I then use in the loop to exclude by ‘continue’)… but I wonder if there is a better method.

    $exclude[] = get_option('page_on_front');
    global $polylang;
    if ( !empty($exclude) && isset($polylang) ) {
    	$langs = array();
    	foreach ($polylang->get_languages_list() as $term)
        		$langs[] = $term->slug;
    	foreach ( $langs as $lang )
    		$exclude[] = pll_get_post($exclude[0],$lang);

    After this, I use the array inside the loop:

    if ( in_array($post->ID, $exclude) )

    (please excuse coding errors, this is not the literal code I’m using but a simplified version)

    Any improvement suggestions would be much appreciated 🙂

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


    You can work at a lower level to obtain what you want.

    $id = get_option('page_on_front'):
    $exclude = $polylang->get_translations('post', $id);

    You will get an array with the languages slugs as keys and the ids of the translations as values (including $id)

    Excellent! Thanks 🙂

    Oh… and what does that return when there is no ID (no page on front) given? an empty array or an array of language slug keys with empty values? and what if there are no languages configured yet?

    Plugin Author Chouby


    Currently it should return an empty string, but I will change this to an empty array in the next version (thanks to your question I saw that I am not consistent)

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘filtering all language front pages from query’ is closed to new replies.