Skip Navigation

[Resolved] Views from another site of multisite

This thread is resolved. Here is a description of the problem and solution.

Problem:
Is it possible to use a View which retrieves data from another part of a multisite?

Solution:
It may be possible with custom coding, but needs testing.

You would use the switch_to_blog function and then the render_view function.

Relevant Documentation:
https://codex.wordpress.org/Function_Reference/switch_to_blog
https://toolset.com/documentation/programmer-reference/views-api/#render_view

This support ticket is created 6 years, 9 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 -
- 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 -

Supporter timezone: Europe/London (GMT+00:00)

This topic contains 3 replies, has 2 voices.

Last updated by Nigel 6 years, 9 months ago.

Assisted by: Nigel.

Author
Posts
#611287

Is it possible to get data from other site in multisite? If I have a custom post type on site B of multisite. Can I make a new view on site A (main site) which shows custom post data from site B?

#611350

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

Hi there

There is no support for that within Toolset, I'm afraid.

It is possible with WordPress to retrieve content from other sites that are part of the same multisite, using the switch_to_blog function (https://codex.wordpress.org/Function_Reference/switch_to_blog) and then running queries such as get_posts or retrieving custom fields with get_post_meta, etc.

But you will need to craft a solution yourself, or contact a developer to do it for you.

(We link to Toolset Contractors in the sidebar, you would need to be clear about your needs because I suspect it is something that many would be unfamiliar with.)

#611646

So, with this switch_to_blog function in php, can I call views render_view() function? Or is the solution limited to wordpress-only functions?

#611657

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

It is not the expected or intended use of Views, but nearly all Views work via standard WordPress functions and use WP_Query, so I expect that they would work. The only way to know for sure is to try.

It is possible that there may be some edge cases, including the upcoming changes to post relationships, where custom database queries are used that might fail, but for most simple Views I expect it would work.

Do let me know how you get on.