<p>I have had success passing an array of <code>siteId =&gt; bool</code> like so <code>$entry-&gt;enabledForSite = ['1 =&gt; false'];</code> and then saving the element.</p>

CC BY-SA 4.0
2023-04-14T20:50:50.020Z
I just figured that out too. That works for me!
Dalton Rooney
CC BY-SA 4.0
2023-04-14T20:50:07.827Z
2023-04-14T20:50:07.827Z
Eric Anderson
<p>I'm not sure setEnabledForSite takes two arguments if you look at the class reference, it seems to only take one.</p>
<p><a href="https://docs.craftcms.com/api/v3/craft-base-element.html#method-setenabledforsite" rel="nofollow noreferrer">https://docs.craftcms.com/api/v3/craft-base-element.html#method-setenabledforsite</a></p>
<p><a href="https://github.com/craftcms/cms/blob/v3/src/base/Element.php#L2832-L2842" rel="nofollow noreferrer">https://github.com/craftcms/cms/blob/v3/src/base/Element.php#L2832-L2842</a>.</p>
<p>I would potentially update your entries criteria to query the entries in the specific site. So something like:</p>
<pre><code>$entries = Entry::find()
        -&gt;section('people')
        -&gt;site('siteHandle')
        -&gt;all();
</code></pre>
<p>Then set in your loop instead:</p>
<pre><code>$entry-&gt;enabled = false;
</code></pre>

CC BY-SA 4.0
2023-04-14T20:48:45.610Z
Even when selecting a specific site in the query, `$entry->enabled = false` disabled the entry for _all_ sites. I actually figured out why it wasn't saving (unrelated issue) but I'm still not clear on how to set the site for `setEnabledForSite()` In the docs it says "This can also be set to an array of site ID/site-enabled mappings" but I'm not clear on the format.
Dalton Rooney
CC BY-SA 4.0
2023-04-15T05:37:03.777Z
@DaltonRooney Ah good to know. thanks for posting an update!
James White
CC BY-SA 4.0
2023-04-14T19:18:26.967Z
2023-04-14T19:18:26.967Z
James White
<p>We have a multi-site setup where we would like to disable a bunch of entries on the primary site only. They entries should still be enabled for the second site. I'm working on a migration that looks like this:</p>
<pre><code>use Craft;
use craft\db\Migration;
use craft\elements\Entry;
</code></pre>
<pre><code>public function safeUp(): bool
    {
        $success = true;

        $entries = Entry::find()
        -&gt;section('people')
        -&gt;all();

        foreach ($entries as $entry) {
            $entry-&gt;setEnabledForSite(false, 1);
            $saved = Craft::$app-&gt;elements-&gt;saveElement($entry);
            if ($saved) {
                echo &quot;$entry-&gt;title saved&quot;;
            } else {
                $success = false;
                echo &quot;$entry-&gt;title could not be saved&quot;;
            }
        }

        return $success;
    }
</code></pre>
<p>The changes aren't saving, however. Any thoughts on why?</p>
<h2>Update</h2>
<p>Based on Eric Anderson's comment below, the final working code is:</p>
<pre><code>public function safeUp(): bool
    {
        $success = true;

        $entries = Entry::find()
        -&gt;section('people')
        -&gt;all();

        foreach ($entries as $entry) {
            $entry-&gt;setEnabledForSite([1 =&gt; false]);
            $saved = Craft::$app-&gt;elements-&gt;saveElement($entry);
            if ($saved) {
                echo &quot;$entry-&gt;title saved&quot;;
            } else {
                $success = false;
                echo &quot;$entry-&gt;title could not be saved&quot;;
            }
        }

        return $success;
    }
</code></pre>

<entries><php><multi-site><migration><status>
How to programatically disable an entry for a specific site
# How to programatically disable an entry for a specific site

(Asked by: username_0 on 2023-04-14)

We have a multi-site setup where we would like to disable a bunch of entries on the primary site only. They entries should still be enabled for the second site. I'm working on a migration that looks like this:
use Craft;
use craft\db\Migration;
use craft\elements\Entry;

public function safeUp(): bool
    {
        $success = true;

        $entries = Entry::find()
        ->section('people')
        ->all();

        foreach ($entries as $entry) {
            $entry->setEnabledForSite(false, 1);
            $saved = Craft::$app->elements->saveElement($entry);
            if ($saved) {
                echo "$entry->title saved";
            } else {
                $success = false;
                echo "$entry->title could not be saved";
            }
        }

        return $success;
    }

The changes aren't saving, however. Any thoughts on why?
Update
Based on Eric Anderson's comment below, the final working code is:
public function safeUp(): bool
    {
        $success = true;

        $entries = Entry::find()
        ->section('people')
        ->all();

        foreach ($entries as $entry) {
            $entry->setEnabledForSite([1 => false]);
            $saved = Craft::$app->elements->saveElement($entry);
            if ($saved) {
                echo "$entry->title saved";
            } else {
                $success = false;
                echo "$entry->title could not be saved";
            }
        }

        return $success;
    }

**Tags:** entries, php, multi-site, migration, status

---

## 2 answers

### Answer by username_1 on 2023-04-14. Score: 3 | Accepted answer

I have had success passing an array of `siteId => bool` like so `$entry->enabledForSite = ['1 => false'];` and then saving the element.

> **Comments:**
> **username_0**: I just figured that out too. That works for me!  

---

### Answer by username_2 on 2023-04-14. Score: 1

I'm not sure setEnabledForSite takes two arguments if you look at the class reference, it seems to only take one.
https://docs.craftcms.com/api/v3/craft-base-element.html#method-setenabledforsite
https://github.com/craftcms/cms/blob/v3/src/base/Element.php#L2832-L2842.
I would potentially update your entries criteria to query the entries in the specific site. So something like:
$entries = Entry::find()
        ->section('people')
        ->site('siteHandle')
        ->all();

Then set in your loop instead:
$entry->enabled = false;

> **Comments:**
> **username_0**: Even when selecting a specific site in the query, `$entry->enabled = false` disabled the entry for _all_ sites. I actually figured out why it wasn't saving (unrelated issue) but I'm still not clear on how to set the site for `setEnabledForSite()` In the docs it says "This can also be set to an array of site ID/site-enabled mappings" but I'm not clear on the format.  
> **username_2**: @DaltonRooney Ah good to know. thanks for posting an update!  

---

