• Hi

    Is there a straight forward way to display content (primarily categorised uploads) from a wpml subsite on the root site? The network will be configured with the subdirectory method.

    This is not to copy the content to the root site, but to get instead to get the text and urls instead.

Viewing 3 replies - 1 through 3 (of 3 total)
  • Moderator bcworkz

    (@bcworkz)

    Yeah, don’t replicate data! ?? (doing so is a pet peeve of mine) You can get subsite data on the root site. I’m unsure if you’d call it straight forward, but it can be done. In PHP you’d call switch_to_blog(). This makes a subsite “current” for query purposes, even though output is for the root site. Any queries made afterwards will be from the now current subsite’s DB. Once you have the desired data, call restore_current_blog() to return queries back to the root site (or which ever site was initially requested, which could have been a different subsite instead of root).

    Thread Starter Castor

    (@castoruk)

    Hi @bcworkz

    Thanks for replying.

    I’ve checked out https://developer.www.ads-software.com/reference/functions/switch_to_blog/, then tried to find some examples or guides online. But it appears to be few and far between on this topic.

    Anything you could suggest I take a look at?

    Moderator bcworkz

    (@bcworkz)

    Sorry, it seems to be a little used technique. In poking around a bit, I did find https://developer.www.ads-software.com/reference/functions/get_blog_post/, which is a bit of a shortcut that might help a little. From the example on the page:

    $post_6 = get_blog_post( 3, 6 );
     
    if ( $post_6 ) {
        echo $post_6->post_title;
    }

    If that were added to a main site’s page template, the title of post 6 from blog 3 would be output.

    More example code and a hint at what not to do:
    https://stackoverflow.com/questions/17611289/wordpress-using-switch-to-blog

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Display subsite content on root site’ is closed to new replies.