-
-
Notifications
You must be signed in to change notification settings - Fork 547
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Incorrect Filtering Behavior in Multisite Setup for Related Entries with "Select Across Sites" Disabled #11307
Comments
Related to #3528. |
I wrote a workaround to get the pagination to work properly at least. On a larger scale this might not be super performant but for me and my case it works pretty well. <?php
namespace App\Scopes;
use Statamic\Query\Scopes\Scope;
use Statamic\Entries\Entry;
use Statamic\Facades\Site;
class AuthorWithArticlesScope extends Scope
{
/**
* Apply the scope.
*
* @param \Statamic\Query\Builder $query
* @param array $values
* @return void
*/
public function apply($query, $values)
{
$currentLocale = Site::current()->handle();
// Fetch all authors
$authors = Entry::query()
->where('collection', 'authors')
->get();
// Filter authors who have at least one article in the current locale
$filteredAuthors = $authors->filter(function ($author) use ($currentLocale) {
$articleIds = $author->get('articles');
if (!is_iterable($articleIds) || empty($articleIds)) {
return false;
}
// Fetch articles that belong to this author and are in the current locale
$articles = Entry::query()
->whereIn('id', $articleIds)
->where('locale', $currentLocale)
->get();
return $articles->isNotEmpty(); // Keep the author if they have articles in the current locale
});
// Modify the query to only include filtered author IDs
$query->whereIn('id', $filteredAuthors->pluck('id')->toArray());
}
} |
And my workaround for the sitemap with the mitydigital/sitemapamic package is using a computed value like so: Collection::computed('authors', 'meta_include_in_xml_sitemap', function (Entry $entry) {
$article_ids = $entry->get('articles');
if (!is_iterable($article_ids) || empty($article_ids)) {
return false;
}
// Fetch all articles in a single query
$articles = Entry::query()
->whereIn('id', $article_ids)
->where('locale', Site::current()->handle())
->get();
return $articles->isNotEmpty(); // Returns true if at least one article matches
}); If anyone needs a workaround for now |
Bug Description
In a multisite setup, the "Entries" field does not respect the
Select Across Sites
setting. WhenSelect Across Sites
is disabled, related entries from other sites are still displayed incorrectly. Specifically, authors are shown with articles from other sites, even when those articles are not present on the current site. This causes thearticles:exists="true"
filter to return inaccurate results.Screenshot 1:
Screenshot 2:
Steps to Reproduce
Result: The article is visible on the authors page, even if it shouldn't
Expected Behavior
Authors without articles on the current site should not be displayed when
articles:exists="true"
is used, especially when "Select Across Sites" is disabled.Actual Behavior
Authors with articles on other sites are still displayed, ignoring the
Select Across Sites
restriction and the current site context.Logs
No relevant logs available.
Environment
Installation
Fresh
statamic/statamic
site via CLI.Additional Details
No additional context provided.
The text was updated successfully, but these errors were encountered: