WordPress.org

Forums

Ambrosite Next/Previous Post Link Plus
[resolved] WPML Patch (22 posts)

  1. greencode
    Member
    Posted 2 years ago #

    I'm using the patch that you posted on http://www.ambrosite.com/plugins/next-previous-post-link-plus-for-wordpress

    But I get the following error (I'd imagine it's because I'm not adding it to the correct place!)

    Parse error: syntax error, unexpected T_FUNCTION, expecting T_WHILE in /home/mysite/public_html/dev/acf/wp-content/plugins/ambrosite-nextprevious-post-link-plus/ambrosite-post-link-plus.php on line 225z

    I replaced this code (on line 204 of version 2.4)

    $result = $wpdb->get_results("SELECT DISTINCT p.* FROM $wpdb->posts AS p $join $where $sort");

    with this code

    global $table_prefix;
    if ( function_exists('icl_sitepress_activate') ) {
    $result = $wpdb->get_results("SELECT DISTINCT p.* FROM $wpdb->posts AS p,{$table_prefix}icl_translations AS icl_translations $join $where
    AND p.ID = icl_translations.element_id AND icl_translations.language_code = '" . ICL_LANGUAGE_CODE . "' $sort");
    } else {
    $result = $wpdb->get_results("SELECT DISTINCT p.* FROM $wpdb->posts AS p $join $where $sort");

    Any ideas?

    http://wordpress.org/extend/plugins/ambrosite-nextprevious-post-link-plus/

  2. ambrosite
    Member
    Plugin Author

    Posted 2 years ago #

    You are missing the closing curly brace at the end of the else clause.

    Errors like that are normally caused by missing braces or semicolons.

  3. greencode
    Member
    Posted 2 years ago #

    Apologies. Could you add the code how it should be. Not sure where the } needs to go.

    Thanks.

  4. ambrosite
    Member
    Plugin Author

    Posted 2 years ago #

    Like this. You missed the last line when you copied the code off my site.

    global $table_prefix;
    if ( function_exists('icl_sitepress_activate') ) {
    $result = $wpdb->get_results("SELECT DISTINCT p.* FROM $wpdb->posts AS p,{$table_prefix}icl_translations AS icl_translations $join $where
    AND p.ID = icl_translations.element_id AND icl_translations.language_code = '" . ICL_LANGUAGE_CODE . "' $sort");
    } else {
    $result = $wpdb->get_results("SELECT DISTINCT p.* FROM $wpdb->posts AS p $join $where $sort");
    }
  5. greencode
    Member
    Posted 2 years ago #

    Umm, replacing the code

    $result = $wpdb->get_results("SELECT DISTINCT p.* FROM $wpdb->posts AS p $join $where $sort");

    on line 204 with

    global $table_prefix;
    if ( function_exists('icl_sitepress_activate') ) {
    $result = $wpdb->get_results("SELECT DISTINCT p.* FROM $wpdb->posts AS p,{$table_prefix}icl_translations AS icl_translations $join $where
    AND p.ID = icl_translations.element_id AND icl_translations.language_code = '" . ICL_LANGUAGE_CODE . "' $sort");
    } else {
    $result = $wpdb->get_results("SELECT DISTINCT p.* FROM $wpdb->posts AS p $join $where $sort");
    }

    causes nothing to display in either default or foreign language.

    I'm using this code to display the previous/next nav

    <div class="nav-arrows-head">
    <div class="nav-previous"><?php previous_post_link_plus( array('order_by' => 'menu_order', 'in_same_cat' => true, 'loop' => true, 'format' => '%link', 'link' => 'Previous') ); ?></div>
    <div class="nav-next"><?php next_post_link_plus( array('order_by' => 'menu_order', 'in_same_cat' => true, 'loop' => true, 'format' => '%link', 'link' => 'Next') ); ?></div>
    </div>

    Any ideas?

  6. ambrosite
    Member
    Plugin Author

    Posted 2 years ago #

    All right, so we fixed the syntax error (first problem solved), but now you are not getting any query results (new problem).

    It is possible that something changed in a recent version of WPML that caused the patch to stop working. But if that is the case, I have no solution for it at the moment. The patch was provided to me by a WPML user. It would be best to pose this question to WPML support.

  7. greencode
    Member
    Posted 2 years ago #

    Okay, thanks. I will do. If I get any results I'll let you know.

  8. Ryan Riatno
    Member
    Posted 2 years ago #

    Hi, any updates on this? I'm experiencing the same problem...

  9. greencode
    Member
    Posted 2 years ago #

    Sorry, I've not looked at this since I last posted as the client doesn't require multilingual functionality just yet.

    Is the problem that you are getting that the previous/next just cycle through all posts and not just those in the selected category?

  10. Ryan Riatno
    Member
    Posted 2 years ago #

    I use custom field as a parameter, the next link in foreign language is wrong its pointing to the main language.

  11. Maxatomik
    Member
    Posted 2 years ago #

    Hi everyone,
    here the patch i used with the last version of WPML and Ambrosite plugin :

    // replace line 204 with the following code
    
    global $table_prefix;
    
    if ( function_exists('icl_sitepress_activate') ) {
    $result = $wpdb->get_results("SELECT DISTINCT p.* FROM $wpdb->posts AS p JOIN {$table_prefix}icl_translations AS icl_translations ON icl_translations.element_id = p.ID $where AND p.ID = icl_translations.element_id AND icl_translations.language_code ='" . ICL_LANGUAGE_CODE . "' $sort");
    
    } else {
    
    $result = $wpdb->get_results("SELECT DISTINCT p.* FROM $wpdb->posts AS p $join $where $sort");
    
    }

    Its an update from de the code above...worked for me :)

  12. Piet Bos
    Member
    Posted 1 year ago #

    This fix doesn't work anymore with the latest versions of everything, at the time of writing:
    WP 3.6
    WPML 2.9.1
    Ambrosite 2.4

  13. greencode
    Member
    Posted 1 year ago #

    @Piet: I'm using 3.5.1, Ambrosite 2.4 and WPML 2.7.1 so obviously these are not the latest versions but have you tried using @Maxatomik's code as that seems to work for me.

  14. Piet Bos
    Member
    Posted 1 year ago #

    @greencode, the fix stopped working after upgrading to WP 3.6/WPML 2.9.1

    I can confirm that before that the fix worked brilliant.

    But I cannot afford to run my code on anything lower than the latest, so that is why I posted that with the latest of everything the fix stopped working.

  15. greencode
    Member
    Posted 1 year ago #

    Let's hope that this get's resolved pretty quickly as I really need to update my versions of WPML and WP but am now slightly reluctant in doing so until this is resolved as the site relies on this working.

  16. ambrosite
    Member
    Plugin Author

    Posted 1 year ago #

    Has anyone tested whether the same problem exists with the core next/previous link functions? This would be incredibly easy to test and would only take five minutes -- just replace next_post_link_plus with next_post_link and check the results.

    If WPML does work with the core functions, then that probably means there is a filter somewhere in the WPML code that makes it work. If that were the case, it should be a fairly simple matter to copy that filter and adapt it to my plugin.

  17. Piet Bos
    Member
    Posted 1 year ago #

    next_post_link works, but obviously without the additional parameters that your plugin offers.
    WP 3.6
    WPML 2.9.2
    Ambrosite Next/Previous Post Link Plus 2.4

  18. ambrosite
    Member
    Plugin Author

    Posted 1 year ago #

    Okay, that is a very interesting and important piece of information. I don't have the latest version of WPML any more, but I'll see if I can get it from the devs. Then I'll do a search for a filter like I described.

  19. ambrosite
    Member
    Plugin Author

    Posted 1 year ago #

    My guess was correct -- there are filters in the WPML code that are making the core next/previous functions work.

    I am not 100% sure about this, but I think if you paste the following five lines at the end of my plugin (or in your functions.php), they should attach the WPML filters to my plugin, which should (hopefully) solve the problem:

    global $sitepress;
    add_filter('get_previous_post_plus_join', array($sitepress,'get_adjacent_post_join'));
    add_filter('get_next_post_plus_join', array($sitepress,'get_adjacent_post_join'));
    add_filter('get_previous_post_plus_where', array($sitepress,'get_adjacent_post_where'));
    add_filter('get_next_post_plus_where', array($sitepress,'get_adjacent_post_where'));
  20. ambrosite
    Member
    Plugin Author

    Posted 1 year ago #

    I should clarify: you need to add these lines to a clean, unpatched version of my plugin.

  21. Piet Bos
    Member
    Posted 1 year ago #

    That seems to work excellent!

    Thanks so much for fixing it!

  22. ambrosite
    Member
    Plugin Author

    Posted 1 year ago #

    Piet, that is excellent news! Thanks for testing and reporting your findings.

    This should be a final and permanent fix -- since it uses WPML's filters, it will be automatically updated whenever WPML is updated. I'd still like to hear feedback from a few other people, but assuming it works for everyone, I'll add it to the next version of my plugin.

Topic Closed

This topic has been closed to new replies.

About this Plugin

  • Ambrosite Next/Previous Post Link Plus
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic

Tags