WordPress.org

Ready to get started?Download WordPress

Forums

Polylang
wp_list_pages(): how to EXCLUDE different languages? (3 posts)

  1. IanFox
    Member
    Posted 2 years ago #

    How can I exclude posts of other languages with wp_list_pages(); ?

    I query a custom post type "product", which has the same properties of a page. I need to have tree with hierarchy.

    adding 'lang' => 'nl', does not work.

    This is the code I have now.

    <?php $args = array(
    	'depth'        => 0,
    	'show_date'    => '',
    	'date_format'  => get_option('date_format'),
    	'child_of'     => 0,
    	'exclude'      => '',
    	'include'      => '',
    	'title_li'     => '',
    	'echo'         => 1,
    	'authors'      => '',
    	'sort_column'  => 'menu_order, post_title',
    	'link_before'  => '',
    	'link_after'   => '',
    	'walker'       => '',
    	'post_type'    => 'product',
        'post_status'  => 'publish'
    ); ?>
    <?php wp_list_pages($args); ?>

    Thank you.

    Ian

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

  2. IanFox
    Member
    Posted 2 years ago #

    wp_query does filter the language, so I figured I'd use include to filter the language... Is there a shorter/faster/better way?

    <?php
    	$ids = "";
    	$args_loop = array('post_type' => 'product');
    	$loop = new WP_Query( $args_loop );
    	if ( $loop->have_posts() ) :
    	while ( $loop->have_posts() ) : $loop->the_post();
    	$ids .= $post->ID . ',';
    	endwhile;
    	endif;
    ?>
       <?php $args = array(
    	'depth'        => 0,
    	'show_date'    => '',
    	'date_format'  => get_option('date_format'),
    	'child_of'     => 0,
    	'exclude'      => '',
    	'include'      => $ids,
    	'title_li'     => '',
    	'echo'         => 1,
    	'authors'      => '',
    	'sort_column'  => 'menu_order, post_title',
    	'link_before'  => '',
    	'link_after'   => '',
    	'walker'       => '',
    	'post_type'    => 'product',
        'post_status'  => 'publish'
    ); ?>
    		<?php wp_list_pages($args); ?>

    Thanks,

    Ian

  3. Chouby
    Member
    Plugin Author

    Posted 1 year ago #

    Polylang currently does not filter other post types than 'page' for wp_list_pages. Unfortunately the filter used to exclude pages does not know about the post types... Could you try this ?
    Edit polylang/include/base.php at line 226 (0.8.9) and replace

    'post_type' => 'page',

    by

    'post_type'   => array_intersect(get_post_types(array('hierarchical' => 1)), $this->post_types),

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic

Tags