[resolved] get_permalink isn't multisite aware (6 posts)

  1. salientdigital
    Posted 4 years ago #

    I have a network of 15 sites, running Domain Mapper for each at its own unique URL. Say DomainA.com is my default domain and I have DomainB.com through DomainO.com.

    I have a custom contact form widget that generates its action attribute like so:

    <form id="contact_widget" method="post"
    action="<?php get_permalink(get_page_by_title('Send Contact')->ID) ?>">

    which works only on the default site...

    In short I just discovered that get_permalink ignores the multisite domain that it is on, get_page_by_title only looks in wp_posts (not the domain's wp_2_posts or wp_3_posts, etc.

    How do I get a permalink for a post title 'Send Contact' on the same domain I am on within a multisite, or a permalink to a post on another site in the network?

    It doesn't seem possible without writing my own SQL to find the post manually with something like

    $table = "wp_".get_current_blog_id()."_posts";

    It seems this would be a useful feature and I am rather surprised it is missing... any ideas?

  2. That's not correct... Get_permalink should be aware, unless you're calling it from a separate site.

  3. Your code is incorrect.

  4. salientdigital
    Posted 4 years ago #

    Yeah - weird. After restarting Apache it worked fine :-/

  5. affilisites
    Posted 4 years ago #

    I have a related problem. When I try switch_to_blog() to the main site and then get_permalink or directly with just get_blog_permalink() I get the URL without the /blog prefix that the main site is supposed to have.
    This only happens when I try to access a permalink for the main blog from a different blog, but when calling it from within the main blog it works okay.

  6. affilisites
    Posted 4 years ago #

    I just realized, the issue above only happens with custom post types, regular posts seem to be fine.

Topic Closed

This topic has been closed to new replies.

About this Topic