• Resolved Simone De Gasperin

    (@simonedegasperin)


    Hi,

    I’m using the WordPress Popular Posts plugin on a multilingual site with WPML, but I’m encountering an issue: the widget shows posts from all languages instead of filtering posts by the current language.

    This is the code I’m using to display the popular posts:

    <?php 
    $args = array(
    'wpp_start' => '<ol style="padding: 0;">',
    'wpp_end' => '</ol>',
    'post_html' => '<li style="list-style: none;" class="list-popolari">
    <div class="flex-display responsive-popolari">
    <div class="col-30 anteprima-articoli1">{thumb}</div>
    <div class="col-70 col-70-popolari">
    <a href="{url}"><h3>{text_title}</h3></a>
    <p class="scrittoda">
    <i class="far fa-calendar-alt"></i>{date}
    </p>
    <p>{summary}</p>
    </div>
    </div>
    </li>
    <hr class="hr-articoli">',
    'thumbnail_width' => 400,
    'thumbnail_height' => 300,
    'excerpt_length' => 350,
    'stats_date' => 1,
    'stats_date_format' => 'j F, Y',
    'limit' => 3,
    'title_length' => 60
    );

    if (function_exists('wpp_get_mostpopular')) {
    $popolari = wpp_get_mostpopular($args);
    }
    ?>

    I’ve tried adding a filter to display posts based on the current language (using wpp_query_posts with WPML), but it doesn’t seem to work.

    Is there an official or recommended way to make the plugin display posts only in the current language when using WPML? Could you provide an example implementation or guidance on how to configure this correctly?

    Thanks in advance for your help!

    The page I need help with: [log in to see the link]

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

    (@hcabrera)

    Hi @simonedegasperin,

    From the Description page:

    Polylang & WPML 3.2+ support – Show the translated version of your popular posts!

    What this means is that WordPress Popular Posts expects all posts to have a translation available in the current language. If none are available, it’ll display the post in its original language instead. Hence why you’re seeing some posts in their original language.

    In short: there’s no way to “filter” posts by language. Posts need to have a translation available in the current language.

    Thread Starter Simone De Gasperin

    (@simonedegasperin)

    In the WPML settings, I have configured it so that only translated posts are visible. Using WP_Query and get_posts(), everything works correctly. Can’t I achieve the same result here?

    You can see a screenshot at this link: https://ibb.co/Vm2Q8GL

    Plugin Author Hector Cabrera

    (@hcabrera)

    No, unfortunately the plugin currently doesn’t provide such a feature. Might implement it in the future though.

    Thread Starter Simone De Gasperin

    (@simonedegasperin)

    Ok, thanks for the reply. Could I use get_posts() to retrieve popular posts somehow?

    Plugin Author Hector Cabrera

    (@hcabrera)

    Can’t see how using get_posts() would solve your problem but to answer your question:

    #1 Add this function to your theme’s functions.php file.

    #2 Use it with get_posts() like so:

    $popular_post_ids = wp2431_get_popular_posts_ids(['limit' => 3]);

    if ( $popular_post_ids ) {
    $popular_posts = get_posts([
    'include' => $popular_post_ids
    ]);

    // Loop here ...
    } else {
    // No popular posts were found, do something else ...
    }
Viewing 5 replies - 1 through 5 (of 5 total)

The topic ‘Filter Posts by Current Language (WPML)’ is closed to new replies.