Compatibility with Post Indexer and Recent Global Posts Widget

We are using Post Indexer, Recent global posts widget and Domain Mapping plugins.

When we show the posts widget, the URL links point to the unmapped location.

For example:

Unmapped blog url:
Mapped blog url:

In the recent global posts widget the url points to, we want it to point to the mapped url.

Of course when the user gets to he is redirected to the mapped URL but it would be better to skip this step altogether.

  • Hoang Ngo
    • Code Slayer

    Hi @IDGIT,

    I hope you are well today and I'm sorry about the issue.

    This code will help, please add this code to your theme functions.php or use mu-plugins

    add_filter( 'post_link', 'fix_domain_mapping_link', 10, 3 );
    function fix_domain_mapping_link( $permalink, $post, $leavename ) {
    	if ( defined( 'DOMAINMAPPING_SUNRISE_VERSION' ) ) {
    		$blog_id = get_current_blog_id();
    		switch_to_blog( 1 );
    		global $wpdb;
    		$sql    = 'SELECT * FROM ' . $wpdb->prefix . 'domain_mapping WHERE blog_id=%d';
    		$record = $wpdb->get_row( $wpdb->prepare( $sql, $blog_id ) );
    		if ( ! empty( $record ) ) {
    			//get the domain
    			$domain_mapped = $record->domain;
    			$domain = parse_url(get_site_url(), PHP_URL_HOST);
    			return str_replace($domain,$domain_mapped,$permalink);
    	return $permalink;

    If you have any issues please don't hesitate to let us know so we can assist
    Best regards,

  • Patrick
    • Support Monkey

    Hi there @IDGIT

    I hope you're well today!

    Is the code @Hoang Ngo provided still working for you?

    We really appreciate your patience on this issue and this should find its way into an update as soon as the current workload allows for it.

    I've sent a reminder to the developer though. :slight_smile:

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.