• Resolved gszabi

    (@gszabi)


    <?php
    // Define custom query parameters
    $custom_query_args = array( /* Parameters go here */ );

    // Get current page and append to custom query parameters array
    $custom_query_args[‘paged’] = get_query_var( ‘paged’ ) ? get_query_var( ‘paged’ ) : 1;
    $custom_query_args[‘cat’] = ‘3’;
    $custom_query_args[‘posts_per_page’] = 5;
    $custom_query_args[‘lang’] = “hu”; //with this i got nothing

    // Instantiate custom query
    $custom_query = new WP_Query( $custom_query_args );

    // Pagination fix
    $temp_query = $wp_query;
    $wp_query = NULL;
    $wp_query = $custom_query;

    ?>
    This query gives me nothing however if i dont use the lang argument it gives me the ukrainian and hungarian posts both.

    Used in home.php

    Thank you in advance

    https://wordpress.org/plugins/polylang/

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

    (@chouby)

    Hi!

    You are querying the category 3 which should already have its own language. Let say English. So you are attempting to query all posts in Hungarish which are also in an English category. There are not.

    If you specify a category, you must not use the ‘lang’ parameter. Normally, Polylang should automatically translate your category in the current language. If it doesn’t work you can use pll_get_term to translate your category id in the language you want.

    Thread Starter gszabi

    (@gszabi)

    Thank you very very much! I didnt thought that the cat id has different number for each langs. Thanks thanks thanks! 🙂

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Custom query with lang argument empty’ is closed to new replies.