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

    (@chouby)

    Hi!

    I don’t use Jetpack myself but I aim to make Polylang compatible with this plugin. Here is a small plugin which may help:

    <?php
    
    /*
    Plugin name: Polylang Jetpack Related Posts
    */
    
    if ( function_exists( 'pll_get_post_language' ) )
    add_filter( 'jetpack_relatedposts_filter_has_terms', 'pll_jetpack_relatedposts_filter_has_terms', 10, 2 );
    
    function pll_jetpack_relatedposts_filter_has_terms( $terms, $post_id ) {
    	$term_id = pll_get_post_language( $post_id, 'term_id' );
    	$terms[] = get_term( $term_id, 'language' );
    	return $terms;
    }

    Once it is activated, there should be a way in Jetpack option to reindex the related posts. According to the documentation, it is located under Jetpack → Debug (link in the footer) → Reindex.

    Please tell me if it solves your issue. If so, I will include the code in Polylang.

    EDIT: I edited the code as there was a bug in the initial version

    Thread Starter robject

    (@robject)

    It seems no related posts appear at all now.
    Note that my site is part of a WordPress multisite installation.
    The url is https://www.reflektis.com/blog-en for the blog articles that I want to show related posts.

    Plugin Author Chouby

    (@chouby)

    I ended up to make my own tests and I confirm the issue. Please keep the plugin active. I am in contact with the Jetpack team to try to understand what’s wrong.

    Plugin Author Chouby

    (@chouby)

    I made a new version that seems to work:

    <?php
    
    /*
    Plugin name: Polylang Jetpack Related Posts
    */
    
    if ( function_exists( 'pll_get_post_language' ) )
    add_filter( 'jetpack_relatedposts_filter_filters', 'pll_jetpack_relatedposts_filter_filters', 10, 2 );
    
    function pll_jetpack_relatedposts_filter_filters( $filters, $post_id ) {
    	$slug = sanitize_title( pll_get_post_language( $post_id, 'name' ) );
    	$filters[] = array( 'term' => array('taxonomy.language.slug' =>  $slug ) );
    	return $filters;
    }

    You have to reindex your posts. if debug->reindex does not work, try to change the status of your posts from published to draft then published again (using the bulk action).

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Polylang and Related Posts plugin’ is closed to new replies.