I have a multisite on Craft 3 and I was wondering how to get section content from another site? Let's say I'm on a default site and I want to get contact content from site with handle siteA?
Can this be done?
Craft CMS Stack Exchange is a question and answer site for administrators, end users, developers and designers for Craft CMS. It only takes a minute to sign up.
Sign up to join this communityFrom a template you could do:
{% set entries = craft.entries.section('jobs').site('siteA').all() %}
In your follow up comment, you're passing craft.entries
as an element to relatedTo
, but that's just going to be an instance of the ElementQuery
class. You need to give it the actual element you're interested in finding the relationship to.
{%set entries = craft.entries({ section: 'jobs', siteId: 2}).all() %}
Downside is, that I need to retrieve id not use handle.
$site = Craft::$app->sites->getSiteByHandle('your-handle');
and in your query you include$elementQuery->siteId = $site->id
craft.entries.section('jobs').relatedTo({ element: craft.entries, sourceSite: 1});