Forum Replies Created

Viewing 2 replies - 1 through 2 (of 2 total)
  • 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

    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’);

Viewing 2 replies - 1 through 2 (of 2 total)