• Resolved Lukasz

    (@wpfed)


    Hi, I’m trying to exclude the current post from displaying in the popular post list, I’m using Polylang plugin, this code works in English, but not in French:

    $args = array(
    	'post_type'   => 'post',
    	'limit'       => 3,
    	'cat'         => '52,46,42,50,54,44,48',
    	'pid'         => array( $post->ID ),
    	'stats_views' => 0,
    	'range'       => 'all',
    	'freshness'   => 1,
    	);
    wpp_get_mostpopular( $args );

    Any suggestions? thanks.

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

    (@hcabrera)

    Hi @wpfed,

    The problem here is that WordPress Popular Posts stores the ID of the original post in the database, not the ID of the translated one. This the reason why your code works when viewing your post in English but not in French (WPP won’t find the ID of the translated post in its database table, hence it’ll be ignored).

    You need to pass WPP the ID of the original post instead to thewpp_get_mostpopular() function. To retrieve it, you can use Polylang’s pll_get_post() function in conjunction with the pll_default_language() function:

    <?php
    $current_post_id = pll_get_post(
        $post->ID,
        pll_default_language()
    );
    
    $args = array(
        'post_type'   => 'post',
        'limit'       => 3,
        'cat'         => '52,46,42,50,54,44,48',
        'pid'         => array( $current_post_id ),
        'stats_views' => 0,
        'range'       => 'all',
        'freshness'   => 1,
        );
    
    wpp_get_mostpopular( $args );
    ?>

    For more details please check Polylang’s documentation: https://polylang.wordpress.com/documentation/documentation-for-developers/functions-reference/

    • This reply was modified 4 years, 10 months ago by Hector Cabrera. Reason: Fixed typo
    Thread Starter Lukasz

    (@wpfed)

    Thanks @hcabrera, that solved it for me! That makes sense, I initially used pll_get_post function but did not add pll_default_language to it.

    Thanks again!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Excluding post using PID arg, works in English but not french (Polylang)’ is closed to new replies.