• Resolved almostpitt

    (@almostpitt)


    I am trying to get the permalink of a page based on two things:

    1) The ml_source_elementid, which identifies the grouping of pages. (i.e. About Us (EN), Sobre Nos (PT)). This I know ahead of time. In this case it is 92.

    2) The current language. This I can do by calling

    mlp_get_current_blog_language(true);
    I have been able to get the permalink using the WordPress general

    <?php
    $url = get_the_permalink(92);
    $current_lang = mlp_get_current_blog_language(true);
    $ml_permalink = apply_filters(‘ml_permalink’, $url , $current_lang );
    echo $ml_permalink
    ?>
    Any idea if I can apply these sorts of filters to get the link? Or is there a better way to do this?

    Thanks!!

Viewing 1 replies (of 1 total)
  • Plugin Support dinamiko

    (@dinamiko)

    Hi almostpitt,

    I order to get the permalinks of the related posts, you can use get_translations api, here is an example:

    add_filter('the_content', function($content) {
    	var_dump(mlp_custom_get_language_items());
    	return $content;
    });
    
    function mlp_custom_get_language_items() {
    
    	$api = apply_filters( 'mlp_language_api', NULL );
    	if ( ! is_a( $api, 'Mlp_Language_Api_Interface' ) ) {
    		return;
    	}
    
    	/**
    	 * @type int    $site_id      Base site
    	 * @type int    $content_id   post or term_taxonomy ID, *not* term ID
    	 * @type string $type         @see Mlp_Language_Api::get_request_type()
    	 * @type bool   $strict       When TRUE (default) only matching exact
    	 *                                 translations will be included
    	 * @type string $search_term  If you want to translate a search
    	 * @type string $post_type    For post type archives
    	 * @type bool   $include_base Include the base site in returned list
    	 */
    	$translations_args = array(
    		'strict'       => FALSE,
    		'include_base' => TRUE,
    	);
    	$translations      = $api->get_translations( $translations_args );
    	if ( empty( $translations ) ) {
    		return;
    	}
    
    	$items = array();
    	/** @var Mlp_Translation_Interface $translation */
    	foreach ( $translations as $site_id => $translation ) {
    
    		$url = $translation->get_remote_url();
    		if ( empty( $url ) ) {
    			continue;
    		}
    
    		$language = $translation->get_language();
    		$active   = FALSE;
    		if ( get_current_blog_id() === $site_id ) {
    			$active = TRUE;
    		}
    
    		$items[ $site_id ] = array(
    			'url'    => $url,
    			'http'   => $language->get_name( 'http' ),
    			'name'   => $language->get_name( 'native' ),
    			'active' => $active,
    		);
    	}
    
    	return $items;
    }

    Thanks,
    Emili

    • This reply was modified 6 years ago by dinamiko.
Viewing 1 replies (of 1 total)
  • The topic ‘How to Get Linked Elements for a specific ml_source_elementid’ is closed to new replies.