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
ElementQuery::site/siteId: Allow multiple? #2854
Comments
Correct. I guess I should take this as a feature request? |
It'd be nice to be able to pass in |
Yep, guess so.
|
Doh, that is a doc bug; fixed for the next release. Just as you couldn’t select elements from more than one locale in Craft 2, you can’t (currently) select elements from more than one site at a time in Craft 3. Will look into what it would take to change that, though. |
This request was posted in May. Is it being developed or do I need to look for other solutions to solve this problem? |
Not currently being developed, no. |
I proposed the ideas on my accidental duplicate of the following.
|
Damn, I need this too now :D |
I also need this! |
I needed this too so I've used the Twig array merge filter for the interim along with the excellent superSort plugin to sort the merged arrays back into chronological order. Here's a simplified version:
|
Yup. I’ve discovered that we need the ability to run an entries query across multiple Sites. Where is the preferred place to add feature requests these days? |
Just pushed up the To update to it, change your "require": {
"craftcms/cms": "^3.2.0-alpha.1",
"...": "..."
} Then run As of d017022 you can pass multiple site handles to the When you query across multiple sites, any elements that are enabled for multiple sites will be returned multiple times (once per site). This is great for cases when you want to create a language picker and get all of the localized versions of an entry at once. However there are cases where that wouldn’t be desired, so we’ve also added the {% set entries = craft.entries()
.section('news')
.site('*')
.unique()
.all() %} |
We just tagged |
Hi, would it be possible to give a little more info on how to "create a language picker and get all of the localized versions of an entry at once". This is exactly what I need. I'm using element-api and have an endpoint and need to get the slug of all entries on other sites/locales with the same id to pipe into a language switcher (in a static site generator build). Below I'm attempting get the slug for the same entry on all sites but incorrectly. I'm attempting something like:
|
I managed to get the appropriate slug using the following (only selecting one 'site'):
and then:
Although I updated to the release/tag stated above the '*' selector for all sites didn't work. It's not a problem for the work i'm currently doing as we only have one other language but will be adding others in the next phase of the project so would be helpful to know why it's not working. I updated composer etc |
@boxadesign If I’m understanding you correctly, this is how you’d do it: 'slugs/<entryId:\d+>.json' => function(int $entryId) {
$excludeSite = Craft::$app->request->getQueryParam('site');
return [
'elementType' => Entry::class,
'criteria' => [
'id' => $entryId,
'site' => $excludeSite ? ['not', $excludeSite] : '*',
],
'transformer' => function(Entry $entry) {
return [
'site' => $entry->site->handle,
'slug' => $entry->slug,
];
}
];
}, With that endpoint in place, you could go to |
@brandonkelly Thanks for that it's very helpful. I definitely can't get the '*' to get all sites working though. This is after following your instructions of using the alpha release. |
@boxadesign It’s working on my end. Can you email support@craftcms.com so we can help troubleshoot from there? |
@brandonkelly but it is not possible to have relations in the CP for that? |
@davidhellmann Maybe you’re looking for #3584? (Also on the list for 3.2.) |
This is a helpful addition when working with craft in combination with craftql! |
@seamofreality Global sets support the same multi-site query improvements that other localizable element types get in 3.2. |
Unless I'm missing something - it would seem it is impossible to select elements from multiple sites with
ElementQuery
.Both
site
andsiteId
seem to only accept scalar values, and passingnull
seems to only select the default/current site elements.Craft CMS 3.0.5
The text was updated successfully, but these errors were encountered: