Forum Replies Created

Viewing 2 replies - 1 through 2 (of 2 total)
  • I actually had to change things a bit. instead of just replacing the $postid I had to create a new variable called $resultid as follow just before getting the post itself.

    $resultid = tptn_object_id_cur_lang( $result->ID );

    And then replace all instances of $result->ID.

    So, I reverted back the line above modifying the $postid.

    I also had to add logic to remove duplicate entries. So, if I already had a link I would ignore it.

    Here’s the snippet.

    $processed_results = array();
    
    foreach ( $results as $result ) {
        $resultid = tptn_object_id_cur_lang( $result->ID );
    
        if ( in_array( $resultid, $processed_results ) ) {
            continue;
        }
    
        array_push ( $processed_results, $resultid );
    
        $sumcount = $result->sumCount;

    I tried the suggested function but it did not work for me. I expected to have the same top 10 regardless of language.

    So, instead, I opted to add the following function at the end of top-10.php.

    /**
     * Returns the object identifier for the current language (WPML).
     */
    function tptn_object_id_cur_lang( $post_id ) {
        if ( function_exists( 'icl_object_id' ) ) {
            return icl_object_id( $post_id, 'any', true, ICL_LANGUAGE_CODE );
        } else {
            return $post_id;
        }
    }

    And replace the line that gets the $postid as indicated below.

    /**
     * Filter the post ID for each result. Allows a custom function to hook in and change the ID if needed.
     *
     * @since	1.9.8.5
     *
     * @param	int	$result->ID	ID of the post
     */
    $postid = tptn_object_id_cur_lang( apply_filters( 'tptn_post_id', $result->ID ) );

    It would be great if you can find a way to include such a fix in the plugin to add support for WPML. Perhaps not exactly as I implemented it, but instead something that would be more generic.

Viewing 2 replies - 1 through 2 (of 2 total)