PLEASE SEE MY REPLY BELOW THIS ONE! THIS IS MOSTLY SOLVED
Thank you for you answer, @alwaysblank.
Sorry, my post was misleading as I used the term “page” instead of “site”. In both cases I mean a single site in the Multisite network. I corrected it in the post above.
I’m heavily using Controller to build custom queries such as this one:
public function products($add_args = []) {
$args = array(
'post_type' => 'products',
'post_status' => 'publish',
'posts_per_page' => -1,
'orderby' => 'menu_order',
'order' => 'ASC',
'en_fallback' => true // Fallback to EN
);
$args = array_merge($args, $add_args);
$products = new \WP_Query($args);
// Add fallback link to objects
foreach ($products->posts as $product) {
$product->link = Polylang::get_permalink($product);
$product->title = get_the_title($product->ID);
$product->markets = SingleProducts::get_product_markets($product->ID);
$product->technical_specifications = SingleProducts::get_product_taxonomy( $product->ID, 'technical_specifications' );
$product->technologies = SingleProducts::get_product_taxonomy( $product->ID, 'technologies' );
$product->key_strengths = SingleProducts::get_product_taxonomy( $product->ID, 'product_key_strengths' );
$product->options = SingleProducts::get_product_taxonomy( $product->ID, 'product_options' );
$product->categories = SingleProducts::get_product_taxonomy($product->ID);
$product->main_category = isset($product->categories[0]) ? $product->categories[0] : [];
// Add a string of all filter slugs
$product->filters = implode(' ', array_map(function($filter) {
if(is_object($filter)) {
return $filter->slug;
} else {
return $filter;
}
}, array_merge(
$product->markets,
$product->categories,
$product->technologies,
$product->technical_specifications
)));
}
return $products->posts;
}
The query arg en_fallback
is used within a pre_get_post
filter which allows me to have English as fallback language with Polylang.
And this is working just fine as I can use $products
in my blade templates to loop through the products.
As explained before I need to mix/merge products from both pages and to not only show them as links to the other page, but to have them queried as they would be part of the page to which they actually do not belong. For this I can of cause adjust the function above to loop through each site via switch_to_blog()
but that still does not solve the issue that I need to use single_products.blade.php
to recognize that there is a post to show instead of going to 404.
So let’s say I’m on Site A and open the URL of a product which is saved on Site B I end up on 404.
So I’m wondering how I could hijack that behavior to get Sage recognizing that there is a product to show with all its functionalities.
So opening the product url as explained above should recognize “hey, there is somthing to show” and open the correct template single-products.blade.php
with the body_classes needed to to use JS routes, etc.
I hope that makes it more clear and again I’m looking forward to get some hints.
Thanks in advance,
Philipp