WordPress.org

Support

Support » Plugins and Hacks » Polylang » [Resolved] filtering all language front pages from query

[Resolved] filtering all language front pages from query

  • 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) )
    		continue;

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

    Any improvement suggestions would be much appreciated 🙂

    http://wordpress.org/extend/plugins/polylang/

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

    @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

    @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 ‘[Resolved] filtering all language front pages from query’ is closed to new replies.
Skip to toolbar