Support » Plugin: Display Posts - Easy lists, grids, navigation, and more » Content not displayed, language bug

  • Resolved flavio93zena

    (@flavio93zena)


    Hello, first off thanks for the plugin, as I based a lot of the website I am doing on it.

    I think I found a nasty bug with it though, I’m using Polylang to display stuff in additional languages (Default is Italian, secondary is English).
    I have several pages and categories with Italian, English and so on.
    Now, if I try to display Italian posts inside an English page, the plugin displays nothing at all.
    https://aregai.it/testing-display-posts-ita/
    https://aregai.it/en/testing-display-posts-eng/
    These 2 pages are complete copy/paste of one another, but the one marked as “English” trying to display Italian posts, returns nothing with no errors whatsoever.

    In case you’re wondering, the code I used for that page:
    [display-posts category="smart-label" meta_key="_thumbnail_id" include_author="true" include_excerpt="true" excerpt_length="30" image_size="medium" wrapper="div" wrapper_class="display-posts-listing grid" posts_per_page="1000000"]

    Please let me know if you have any ideas, I really don’t want to have to make all pages in English just to get them to be displayed 🙁
    Thanks in advance!

Viewing 1 replies (of 1 total)
  • Thread Starter flavio93zena

    (@flavio93zena)

    Alright, nevermind 🙂
    For anyone else looking for a solution, here’s what you have to do: https://www.billerickson.net/code/polylang-support-for-display-posts-shortcode/
    Add this to functions.php

    /**
     * Polylang support for Display Posts Shortcode
     *
     * @author Bill Erickson
     * @link https://wordpress.org/support/topic/display-posts-in-a-specific-language/
     *
     * @param array $args, WP Query arguments
     * @param array $atts, Shortcode attributes
     * @return array $args
     *
     */
    function be_polylang_support_dps( $args, $atts ) {
      if( !empty( $atts['lang'] ) )
        $args['lang'] = esc_attr( $atts['lang'] );
      return $args;
    }
    add_filter( 'display_posts_shortcode_args', 'be_polylang_support_dps', 10, 2 );

    And then you want to modify your queries to include the lang parameter as explained here: https://polylang.pro/doc/developpers-how-to/#query

    Final code would be, in my case:
    [display-posts category="smart-label" meta_key="_thumbnail_id" include_author="true" include_excerpt="true" excerpt_length="30" image_size="medium" wrapper="div" wrapper_class="display-posts-listing grid" posts_per_page="1000000" lang="it"]
    Note the lang=”it” at the end.

    Thanks anyway 😀 Let me just post (another) 5 stars review for one of the best plugins for WordPress.

    • This reply was modified 1 year, 5 months ago by flavio93zena.
Viewing 1 replies (of 1 total)
  • The topic ‘Content not displayed, language bug’ is closed to new replies.