WordPress.org

Ready to get started?Download WordPress

Forums

Polylang
[resolved] Custom posts from custom taxonomy on home page (7 posts)

  1. Ayman
    Member
    Posted 1 year ago #

    Hello,

    First of all I would like to thank the author for this great plugin. Than if you please have any suggestions for these 2 questions, would be very appreciated.

    1. I'm showing custom post type from a specific custom taxonomy on my home page using this code:

    <?php
    	$args = array(
    			'posts_per_page' => '6' ,
    			'section' => 'اصداراتنا', // my custom taxonomy
    		);
    	query_posts($args); ?>
            <?php if( is_tax() ) {
                global $wp_query;
                $term = $wp_query->get_queried_object();
                $title = $term->name;
            }  ?>

    My problem is that the posts are always appearing in the default language "AR" and the translation in "IT" or "EN" are not appearing when you switch language.

    Is there any way to retrieve custom post type from a specific custom taxonomy and have them translated when you switch language?

    2. On the home page I have a slider that is a part of the theme I'm using and this slider is based on custom post type that I already ticked it in the plugin settings to make translatable but when switching languages the slides are not appearing at all or if appearing that would be the default language only.

    Any suggestion on how to make the slier works?

    I'm using:
    WordPress 3.5.1
    Polylang 1.0.3

    Homepage: Non static
    Polylang settings:

    • The language is set from content. Posts, pages, categories and tags urls are not modified.
    • Remove /language/ in pretty permalinks
    • Hide URL language information for default language
    • Please note that all the post types and custom taxonomies have languages and translations enabled

      Thank you in advance

    http://wordpress.org/extend/plugins/polylang/

  2. Chouby
    Member
    Plugin Author

    Posted 1 year ago #

    Just after defining the $args, and before querying posts, add this line

    $args = array_merge($GLOBALS['wp_query']->query_vars, $args);

    This will avoid you to completely overwrite the query vars (including the language set by Polylang).

    Check if the code of the slider does not make the same mistake.

  3. Ayman
    Member
    Posted 1 year ago #

    @Chouby thanks for your fast respond.
    I tried adding the line you gave above but it didn't work. now when I switch the language is not showing the default posts of the default language any more.
    I don't know why I didn't work... any idea?

  4. Chouby
    Member
    Plugin Author

    Posted 1 year ago #

    Could you explain?
    Is 'section' your taconomy?
    Is 'اصداراتنا' a term slug in this taxonomy?
    Did you activate the languages and translations management in Polylang settings for this taxonomy?

  5. Ayman
    Member
    Posted 1 year ago #

    Sorry if I didn't explain well..

    Is 'section' your taconomy?

    Yes, "Section" is the custom taxonomy name.

    Is 'اصداراتنا' a term slug in this taxonomy?

    Yes, "اصداراتنا" is a term slug in this custom taxanomy.

    Did you activate the languages and translations management in Polylang settings for this taxonomy?

    Yes, the option that control languages and translations management in Polylang settings for custom taxonomies was activated for this taxonomy.

    Note: If the term "اصداراتنا" is making confusion please replace it in the code with what ever you prefer.

    Thanks for helping @Chouby

  6. Chouby
    Member
    Plugin Author

    Posted 1 year ago #

    OK. So even if the line I asked you to add is still useful, it won't help in your case.

    You are always querying an Arabic term, even on Italian and English pages, so the query result is empty. You need to query the translation of your term in the correct language.

    Polylang will soon do this automatically for you. This is currently an external plugin and I just wrote the custom taxonomy section. Could you test it?

    Paste http://pastebin.com/utLLn1cu in a something.php file, upload it in your plugins directory and activate the newly created plugin.

  7. Ayman
    Member
    Posted 1 year ago #

    @Chouby,

    I did copy and paste the plugin code you gave above into polylang_auto_translate.php file, then I uploaded the file and activated it. and it worked perfectly as expected.

    Thank you for this great plugin and for your help...
    Ps. Please let me know if I can help with ANY testing for new features.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic