• I tweaked the get_pages example code on www.ads-software.com to show the title, page_link and some custom fields of a childpage on the homepage, but the code only returns the content of the default language. I would like the code to retrieve the content of the current language.

    <ul id="latest">
    			 <?php
    				$mypages = get_pages( array( 'child_of' => 23, 'sort_column' => 'menu_order', 'number' => '1', 'offset' => '0', 'sort_order' => 'asc' ) );
    
    				foreach( $mypages as $page ) {
    					$content = $page->post_content;
    					if ( ! $content ) // Check for empty page
    						continue;
    
    					$content = apply_filters( 'the_content', $content );
    				?>
    
    				<li id="latest" style="background: <?php the_field('kleurcode_project', $page->ID); ?>;">
    
    					<h2><a href="<?php echo get_page_link( $page->ID ); ?>" style="color:<?php the_field('kleurcode_tekst', $page->ID); ?>"><?php echo $page->post_title; ?></a></h2>
    
    					<p><a href="<?php echo get_page_link( $page->ID ); ?>" style="color:<?php the_field('kleurcode_tekst', $page->ID); ?>"><?php the_field('short_text', $page->ID); ?></a></p>
    
    					<a href="<?php echo get_page_link( $page->ID ); ?>"><img src="<?php the_field('featured_image', $page->ID); ?>"></a>
    
    				</li>
    				<?php
    				}
    			?>
    
    			</ul>

    I couldn’t find an answer to this question on the forums, I would surely appreciate getting to know the solution.

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

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

    (@chouby)

    Only in default language? get_pages should not even be filtered as explained here. Use the function get_posts instead.

    Thread Starter Thil87

    (@thil87)

    The homepage displays the default language in both languages. All the strings translations do change, but not the items I want.

    Changing get_pages to get_posts didn’t do the trick.

    Plugin Author Chouby

    (@chouby)

    Could you share the code you are using?

    Thread Starter Thil87

    (@thil87)

    The code that I’m using is the code in my first post. It works fine, but only not for the multilingual site.

    Plugin Author Chouby

    (@chouby)

    I meant with get_posts. What is above may help too.

    Thread Starter Thil87

    (@thil87)

    Plugin Author Chouby

    (@chouby)

    I suppose I understood what you want to do. Your get_pages queries only children of the page 23 which I guess is in the default language.

    If you want pages in other languages, you should translate this page and then query children of the translated pages.

    You can use pll_get_post(23) instead of 23 to get the page id of the translation page 23 in the current language.
    See the doc here.

    Thread Starter Thil87

    (@thil87)

    Thanks, that works. However, now I have an issue with the array parameter ‘number’. I want it to select the first 4 child pages based on ‘page order’ with an offset of 1.

    But now I have to put ‘number’ => ’16’ to grab the first 4 pages in one language and 5 pages in English.

    Any clue how to solve this issue?

    To show what’s going on: blossity.nl

    Maybe there is a way better way to this?

    Plugin Author Chouby

    (@chouby)

    As I mentioned above, get_pages is not filtered. It means that it always return all languages. As explained in the topic I linked above, I did this for performance reasons and because it is not needed. So please use the function get_posts instead of get_pages.

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘Get_pages array shows default language’ is closed to new replies.