Support » Plugin: Post Navigator » Possible Fix for WPML

  • I found a potential fix for the compatibility problem with WPML.

    There was an error in the SQL query from the core get_adjacent_post() call.
    Instead in looking in the correct element_type, it was consistently looking for a post_post in the wpx_icl_translations table.

    The fix is to modify the original get_adjacent_post() from the /wp-includes/link-template.php file and add the new function to the class.post-navigator.php

    for example I named mine public static function get_adjacent_any_post(…)

    and after the line
    $join = apply_filters( "get_{$adjacent}_post_join", $join, $in_same_term, $excluded_terms );

    I added the following

    $join = str_replace("post_post", "post_".$post->post_type, $join);
    		$join = str_replace("'post'", "'".$post->post_type."'", $join);

    And now the Next and Previous buttons appear on every post, page and custom post type edition page !

    hope this helps !

    https://wordpress.org/plugins/post-navigator/

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

    (@daroost)

    better yet, just do this in the class __construct :

    add_filter( 'get_previoous_post_join', array( __CLASS__, 'get_adjacent_post_join' ) );
    add_filter( 'get_next_post_join', array(  __CLASS__, 'get_adjacent_post_join' ) );

    the define de function elsewhere in the class

    public static function get_adjacent_post_join( $join )
    {
    	$join = str_replace("post_post", "post_".$post->post_type, $join);
    	$join = str_replace("'post'", "'".$post->post_type."'", $join);
    	return $join;
    }

    or for the theme functions.php

    add_filter( 'get_previoous_post_join',  'get_adjacent_post_join'  );
    add_filter( 'get_next_post_join', 'get_adjacent_post_join'  );
    function get_adjacent_post_join( $join )
    {
    	$join = str_replace("post_post", "post_".$post->post_type, $join);
    	$join = str_replace("'post'", "'".$post->post_type."'", $join);
    	return $join;
    }

    Actually the error is in WPML itself in the get_adjacent_post_join function definition. There is a problem getting the current post_type with this: $post_type = get_query_var( 'post_type' ); of the get_adjacent_post_join function in sitepress.class.php wich always returns “post” even on a “page” post_type !

Viewing 1 replies (of 1 total)
  • The topic ‘Possible Fix for WPML’ is closed to new replies.