• Hi – I’m having an issue getting this to work with the WPML plugin – my english language posts are working as expected on a category archive page, but the translated versions do not. My translations are all one to one, so it’s not a matter of missing content or missing categories, and a regular WP query returns the posts. I’m echo-ing a shortcode in order to load the posts, should I be doing this another way for WPML to work?

    Here’s what I’m using to pull in posts:

    $cat = get_category( get_query_var( 'cat' ) );
    			$category = $cat->slug;
    			$postsNotIn = implode(",", $do_not_duplicate);
    			echo do_shortcode('[ajax_load_more post_type="post" category="'.$category.'" exclude="'.$postsNotIn.'" scroll="false" transition="fade" images_loaded="true" button_label="More Stories" container_type="ul"]');

    Any help would be appreciated!
    Thanks,
    Erin

    https://www.ads-software.com/plugins/ajax-load-more/

Viewing 8 replies - 1 through 8 (of 8 total)
  • Plugin Author Darren Cooney

    (@dcooney)

    I just tested this and I can’t replicate.
    I was able to return FR and EN posts on the separate cat pages.

    Are your categories translated?

    Thread Starter erinallen

    (@erinallen)

    Yes they categories are translated – see:
    https://romanianspring.com/category/culture/books/ vs. https://romanianspring.com/ro/category/cultura/carti/

    The categories themselves are translated and synced, as is the post. This works fine where we’re using a standard WP query, but not where we’re using the plugin.

    Plugin Author Darren Cooney

    (@dcooney)

    You are getting many errors on the french version of the site.
    https://www.dropbox.com/s/8nzhm76ddhsid91/Screenshot%202015-12-22%2012.52.26.png?dl=0

    The most concerning is the 404 error for the admin-ajax.php call.

    Thread Starter erinallen

    (@erinallen)

    Ah ok I see what’s going on – so – to fix – can you tell me how that script being enqueued by the plugin? It’s listing the URL for the file in the language specific URL – instead of pulling from the main site URL or template directory. It’s looking in romanianspring.com/ro/… instead of romanianspring.com/… – is there a place in the plugin where I can edit the enqueueing?

    Plugin Author Darren Cooney

    (@dcooney)

    Its not the enqueue thats the issue.
    The issue is the path to admin-ajax (admin_url(‘admin-ajax.php’)).

    Enqueue starts at line 217 in ajax-load-more.php

    Thread Starter erinallen

    (@erinallen)

    aha – ok, I see what you are saying. I can fix it if I use:

    ‘ajaxurl’ => site_url(‘/wp-admin/admin-ajax.php’)

    instead of

    ‘ajaxurl’ => admin_url(‘admin-ajax.php’)

    so that way it bypasses the “/ro/” part of the admin url – is there any way you know of to fix this? should I pass along to the WPML people too?

    thanks!

    Plugin Author Darren Cooney

    (@dcooney)

    Before switching the core ALM plugin, i’d suggest reaching out to WPML to ask them if they know why to the path to admin-ajax would be modified.

    In order to resolve this issue this is what I have done:

    1. Check for current language and set a variable accordingly:

    jQuery( document ).ready(function() {
    <?php if(ICL_LANGUAGE_CODE=='en'){ ?>
        lg = "en";
    <?php } ?>
    <?php if(ICL_LANGUAGE_CODE=='es'){ ?>
        lg = "es";
    <?php } ?>
    <?php if(ICL_LANGUAGE_CODE=='de'){ ?>
        lg = "de";
    <?php } ?>
    <?php if(ICL_LANGUAGE_CODE=='it'){ ?>
        lg = "it";
    <?php } ?>
    <?php if(ICL_LANGUAGE_CODE=='fr'){ ?>
        lg = "fr";
    <?php } ?>
    });

    2. On each post set a custom field with the language

    usp-custom-15 = fr
    usp-custom-15 = it
    usp-custom-15 = de
    usp-custom-15 = it
    usp-custom-15 = en

    3. Check for meta keys

    [ajax_load_more post_type='post' posts_per_page='1' transition='fade' transition_container='false' container_type='ul' pause='true' pause_override='true' meta_key='usp-custom-15' meta_value=lg meta_compare='IN' meta_type='CHAR' meta_relation='AND' button_label='+']

    Not it will search for posts with those met-keys and one of them was the language.

    • This reply was modified 7 years, 10 months ago by downfast.
Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Not working on secondary language category pages with WPML?’ is closed to new replies.