<p>This is because you are using <code>!==</code> to compare your <code>sectionId</code> and <code>typeId</code>.</p>
<p>In PHP using this will <a href="https://www.php.net/manual/en/language.operators.comparison.php" rel="nofollow noreferrer">compare the value as well as the type</a>.</p>
<p>Here, since you are comparing an <code>int</code> with a <code>string</code>, although the value is a match, the type isn't, your first conditional is failing and nothing happens.</p>
<p>Try using <code>!=</code> instead:</p>
<pre class="lang-php prettyprint-override"><code>Event::on(Entry::class, Element::EVENT_AFTER_SAVE, function (ModelEvent $e) {
  $entry = $e-&gt;sender;

  if ($entry-&gt;sectionId != 7) {
    return;
  }

  if ($entry-&gt;typeId != 9) {
    return;
  }

  $parent = $entry-&gt;getParent();

  if (!$parent) {
    return;
  }

  $parent-&gt;dateUpdated = $entry-&gt;dateUpdated;
  Craft::$app-&gt;getElements()-&gt;saveElement($parent);
});

</code></pre>

CC BY-SA 4.0
2021-08-24T22:24:40.310Z
Oh boy...that was easy. Thank you!!
mupoftpr
CC BY-SA 4.0
2021-08-24T12:41:22.523Z
2021-08-24T12:41:22.523Z
Oli
<p>I'd start by var_dumping or logging the value of sectionId and TypeId, since its not saving parent, it hits one of the if statements and returns before doing anything.</p>

CC BY-SA 4.0
2021-08-24T10:02:26.850Z
2021-08-24T10:02:26.850Z
Syversen
<p>I got a bit of help with this from Discord. Here is what I have:</p>
<pre><code>Event::on(Entry::class, Element::EVENT_AFTER_SAVE, function (ModelEvent $e) {
  $entry = $e-&gt;sender;

  if ($entry-&gt;sectionId !== 7) {
    return;
  }

  if ($entry-&gt;typeId !== 9) {
    return;
  }

  $parent = $entry-&gt;getParent();

  if (!$parent) {
    return;
  }

  $parent-&gt;dateUpdated = $entry-&gt;dateUpdated;
  Craft::$app-&gt;getElements()-&gt;saveElement($parent);
});
</code></pre>
<p>The trouble is that the <code>if</code> conditions aren't working; with the above code, the parent entry is not updated. As soon as I remove those two if statements, the code works and the parent is updated. However, I don't want to run this on all sections/structures.</p>
<p>Does anyone know what might be going wrong? I've checked the section/type IDs many times :)</p>
<p>Thanks in advance!</p>

<entry>
Update parent entry `dateUpdated` on child entry save
# Update parent entry `dateUpdated` on child entry save

(Asked by: username_0 on 2021-08-24)

I got a bit of help with this from Discord. Here is what I have:
Event::on(Entry::class, Element::EVENT_AFTER_SAVE, function (ModelEvent $e) {
  $entry = $e->sender;

  if ($entry->sectionId !== 7) {
    return;
  }

  if ($entry->typeId !== 9) {
    return;
  }

  $parent = $entry->getParent();

  if (!$parent) {
    return;
  }

  $parent->dateUpdated = $entry->dateUpdated;
  Craft::$app->getElements()->saveElement($parent);
});

The trouble is that the if conditions aren't working; with the above code, the parent entry is not updated. As soon as I remove those two if statements, the code works and the parent is updated. However, I don't want to run this on all sections/structures.
Does anyone know what might be going wrong? I've checked the section/type IDs many times :)
Thanks in advance!

**Tags:** entry

---

## 2 answers

### Answer by username_1 on 2021-08-24. Score: 1 | Accepted answer

This is because you are using !== to compare your sectionId and typeId.
In PHP using this will compare the value as well as the type.
Here, since you are comparing an int with a string, although the value is a match, the type isn't, your first conditional is failing and nothing happens.
Try using != instead:
Event::on(Entry::class, Element::EVENT_AFTER_SAVE, function (ModelEvent $e) {
  $entry = $e->sender;

  if ($entry->sectionId != 7) {
    return;
  }

  if ($entry->typeId != 9) {
    return;
  }

  $parent = $entry->getParent();

  if (!$parent) {
    return;
  }

  $parent->dateUpdated = $entry->dateUpdated;
  Craft::$app->getElements()->saveElement($parent);
});

> **Comments:**
> **username_0**: Oh boy...that was easy. Thank you!!  

---

### Answer by username_2 on 2021-08-24. Score: 0

I'd start by var\_dumping or logging the value of sectionId and TypeId, since its not saving parent, it hits one of the if statements and returns before doing anything.


---

