• Hello,

    @nelygus post a great solution for the popular post from different language and ??its perfect works.
    Top 10 Polylang solution

    Now I have another issue which I trying to find out that I have two different languages, English and German. German post (by default ) works perfectly fine but the problem with English post. actually I need a solution for the custom time period which shows the last 180 days English popular post on the list

    for more clearly, I need to show only an English popular post from the last 180 days.

    I really need your great help.

    Thanks

    • This topic was modified 5 years, 7 months ago by fazluldev.
Viewing 4 replies - 1 through 4 (of 4 total)
  • Thread Starter fazluldev

    (@fazluldev)

    In function.php i wrote this data_query but it won’t work that what i looking for.

    `function tptn_filter_posts_per_language($posts){
    global $polylang;
    $args = array(
    ‘posts_per_page’ => 5,
    ‘post_type’ => ‘post’,
    ‘orderby’ => ‘comment_count’,
    ‘order’ => ‘DESC’,
    ‘date_query’ => array(
    ‘after’ => date(‘Y-m-d’, strtotime(‘-180 days’))
    )
    );
    $_posts = get_posts($args);

    /** $_posts = array(); **/

    $limitPostsPerLanguage = 5; // show only 5 posts on home
    $currentLanguage = pll_current_language(‘slug’);

    foreach($posts as $post) {
    $lang = $polylang->model->get_post_language($post[‘ID’])->slug;
    if ($currentLanguage == $lang) {
    $_posts[] = $post;
    }
    if (count($_posts) >= $limitPostsPerLanguage) {
    break;
    }
    }
    return $_posts;
    }
    add_filter(‘tptn_pop_posts_array’,’tptn_filter_posts_per_language’);

    Plugin Author Ajay

    (@ajay)

    Am I right to understand that you want to show the normal period in German but 180 days top posts (or posts posted in the top 180 days) if it is English?

    I’m not familiar with how PolyLang works to be honest. What output are you seeing with your code ?

    Thread Starter fazluldev

    (@fazluldev)

    Am I right to understand that you want to show the normal period in German but 180 days top posts (or posts posted in the top 180 days) if it is English?
    ——-
    >> For German post, your plugin works perfectly.
    >>> In the English post, its already show top popular post but I want to show, top popular post but only for last 180 days!

    I’m not familiar with how PolyLang works, to be honest. What output are you seeing with your code ?
    ——–
    it shows the top popular post but not rendered last 180 days.

    Thanks

    Plugin Author Ajay

    (@ajay)

    I am wondering if it might be easier to do this based on the language of the post and then call the custom function or the shortcode.

    So something along the lines of the below to call the shortcode.

    if lang is English
    do_shortcode( ‘[tptn_list how_old=”180″]’
    else
    do_shortcode( ‘[tptn_list]’

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Top 10 Polylang custom time period’ is closed to new replies.