We upgraded our Toolset account from the single license to the 3-site version. We have two sites set up right now. We have a unique situation in the relationship between these sites where we'd like to keep all our Views on the first site, but to also be able to display the pages we have the View shortcode on work on the second site. Is there any way to make that doable?
What we are trying to achieve is to have the output from views on site one be usable on site two without providing the views code to site two.
I'm not sure if there is any way to achieve this. I know there is the WordPress multisite possibility, but I don't know if that work with Toolset views or exactly how that is set up. If you have any suggestions that would be very helpful for our unique situation. We're trying to provide the system we've developed in all these previous support tickets to the second site without giving up the code that makes the system work. Both sites are the ones under this single Toolset account, if that makes any difference.
Can you edit the title of this ticket to say "Is it possible to share Views generated content across two sites?" I started by having "Sharing Views generated across two sites" as the subject, but then added "Is it possible to" at the start, but forgot to change sharing to share.
A View will query content from the wp_posts table of the site database. Separate sites have separate databases.
A Multisite set-up is a little different, in that there is a single database shared by sub-sites, but each sub-site has it's own database tables (e.g. their own version of wp_posts).
WordPress does provide a means to switch context between sites that you could in theory use before making a query.
You can use switch_to_blog() to change context before running a query, and restore_current_blog to revert context afterwards.
But, Toolset doesn't include any handling for such a scenario.
I'm not sure whether it is feasible to get a View on one site to run on another site (rather than have a View which runs on a site query data from another site).
If there is a solution it will involve those WordPress functions, but I can't say much more than that, I'm afraid.
Using switch_to_blog & restore_current_blog - I think that approach would have us using Views on site #2 to pull data from site #1 and then display the output on site #2. The reverse of that would use Views on site #1 to pull data from site #2, but then it would display the output on site #1. What we're wanting is to use data on site #2 pulled by Views on site #1 and then display the output on site #2. So I'm not sure if that approach would have a way of working. It sounds doubtful.
In a multisite environment, would there be any way to pull the View code itself, rather than data from the database using this switch_to_blog approach? The view code is in the site database as well, so I'm thinking that might be possible. What I'm thinking of here would be to have a set of Views on site #1, then set up Views to correspond to those Views on site #2. The views on site #1 would have the full code. The corresponding views on site #2 would just be placeholder views with the same titles that don't execute anything. We'd then have a custom code snippet that gives a list of IDs for which Views correspond to each other on both sites. Then, also in that custom code, we could say when View Site #2 (9060) is called, for example, then it would check this list to find the ID of the corresponding View in Site #1, pull that code from that using the switch_to_blog approach, and execute that code using the site #2 data and output to site #2.
> In a multisite environment, would there be any way to pull the View code itself, rather than data from the database using this switch_to_blog approach
- I'm afraid, this won't work, because 'switch_to_blog' will only switch the scope or source of the current site for the database query. It doesn't actually maintain 1-1 correspondence or sync between the sites in a multisite environment.
Based on what we've discussed so far, here are some of the options that you have:
1. If your goal is to maintain a sync between the data and the display logic (views, custom code etc) across sites in a network, there are third-party plugins available for this. For example: hidden link
2. If you don't want to share custom code and views (display logic) with the other websites and are also OK with maintaining the post data at the source website only, you can load generated pages from the source website into the other websites through iframes.
( ref: hidden link )
This would mean that the saving/processing of data and generation of output, everything will be originally taking place at the central source website. The other websites will only be loading the read-only copies of those pages.
The sync option will provide the Views code to site #2, so that won't work for our needs.
I tried the iframe option for a bit. It does show the page content as needed without setting up the views on site #2. But I was having problems with getting the display to look good. I'll have to dig in deeper with that if there isn't another option. But the problem there is all the data that the Views use to generate the pages has to be on site #1 as well this way. We were hoping to be able to do that on site #2.
So it's looking like there won't be an ideal option for this. That means I have some uncomfortable decisions to make in our current situation.
This way I can have the Views on Site #2 but I can remove access to the whole Toolset menu in the dashboard from any other admin user. That works to meet my needs here.