Answers.Body: <p>Ok, so this is the relevant code in the service processing the feed, where the stepBeforeElementMatch is being called:</p>
  
  <pre><code>        // Fire an 'onStepBeforeElementMatch' event
          if ($this-&gt;hasEventHandlers(self::EVENT_STEP_BEFORE_ELEMENT_MATCH)) {
              $event = new FeedProcessEvent([
                  'feed' =&gt; $feed,
                  'feedData' =&gt; $feedData,
                  'contentData' =&gt; $matchExistingElementData,
              ]);
  
              $this-&gt;trigger(self::EVENT_STEP_BEFORE_ELEMENT_MATCH, $event);
  
              if (!$event-&gt;isValid) {
                  return;
              }
  
              // Allow event to modify variables
              $feed = $event-&gt;feed;
              $feedData = $event-&gt;feedData;
              $matchExistingElementData = $event-&gt;contentData;
          }
  </code></pre>
  
  <p>I have not tested this, but by the looks of it, it should be enough to set the <code>$event-&gt;isValid</code> to <code>false</code> in your code after doing the necessary checks that you want.</p>
  
  <p>Be aware that the <code>$event-&gt;feedData</code> you are working on is an array representation of your feed data (converted from, XML, JSON or whatever). So you need to do your checks accordingly. At this point, Feed Me has not tried to match against potentially existing elements in Craft. Your example code basically assumes there's a field in the feed element with the name <code>status</code> with the value <code>false</code>. If that's not the case, you could do your checks on whatever you want, before a certain date, etc.</p>
  
  <p>But if it is, something like this would be likely to work (again untested):</p>
  
  <pre><code>if($event-&gt;feedData['status'] == "false") {
  
      $event-&gt;isValid = false;
  }
  
  </code></pre>
  
  <p>If you're looking to skip based on some Craft element, you'd either need to query for it (basically doing some custom matching), or use an event later in the process (I can help you out there too, but maybe it's easier in your case to skip it already here).</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-11-02T16:10:47.943Z
Answers.Text: Thank you for your detailed answer, really appreciate it :)
Answers.UserDisplayName: Christopher Dosin
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-11-02T16:52:12.097Z
Answers.Text: Happy to help, hope it worked out!
Answers.UserDisplayName: KSP
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-10-26T16:41:35.197Z
Answers.LastActivityDate: 2019-10-26T16:47:50.560Z
Answers.LastEditDate: 2019-10-26T16:47:50.560Z
Answers.UserDisplayName: KSP
Body: <p>I want to skip an element within Feed me after if a condition passes.</p>
  
  <p>So i am listening to the <a href="https://docs.craftcms.com/feed-me/v4/developers/events.html#the-stepbeforeelementmatch-event" rel="nofollow noreferrer">stepBeforeElementMatch</a> event.
  Within this event i would have something like this:</p>
  
  <pre><code>if($event-&gt;feedData['status'] == "false") {
  
      // dont import, skip me
  }
  </code></pre>
  
  <p>I couldn't find any way how i would skip this specific element. I am wondering if there is a way to even skip an element?</p>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2019-10-26T15:56:50.023Z
Comments.Text: I have been in the same situation, and it's not entirely trivial. The problem is that quite a few of FeedMe's events doesn't actually take the values changed in the event into account once the event has returned (with a couple of exceptionns). In the end, after dissecting the whole flow of a FeedMe imports, I resolved to doing a couple of small changes to the plugin code and made a pull request. I can post an answer with some pointers. It's quite easy fixes.
Comments.UserDisplayName: KSP
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2019-10-26T16:17:54.317Z
Comments.Text: Second thought – skipping elements to import might be a bit easier, I was trying to shield some entries from being deleted, and that proves a bit more tricky. Anyways, will have a look, and most probably can help out.
Comments.UserDisplayName: KSP
Tags: <plugin-feedme>
Title: Feed Me, skip element
ThreadText: # Feed Me, skip element
  
  (Asked by: username_0 on 2019-10-26)
  
  I want to skip an element within Feed me after if a condition passes.
  
  So i am listening to the [stepBeforeElementMatch](https://docs.craftcms.com/feed-me/v4/developers/events.html#the-stepbeforeelementmatch-event) event.
  Within this event i would have something like this:
  
  ```
  if($event->feedData['status'] == "false") {
  
      // dont import, skip me
  }
  
  ```
  
  I couldn't find any way how i would skip this specific element. I am wondering if there is a way to even skip an element?
  
  **Tags:** plugin-feedme
  
  > **Comments:**
  > **username_1**: I have been in the same situation, and it's not entirely trivial. The problem is that quite a few of FeedMe's events doesn't actually take the values changed in the event into account once the event has returned (with a couple of exceptionns). In the end, after dissecting the whole flow of a FeedMe imports, I resolved to doing a couple of small changes to the plugin code and made a pull request. I can post an answer with some pointers. It's quite easy fixes.  
  > **username_1**: Second thought – skipping elements to import might be a bit easier, I was trying to shield some entries from being deleted, and that proves a bit more tricky. Anyways, will have a look, and most probably can help out.  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2019-10-26. Score: 2 | Accepted answer
  
  Ok, so this is the relevant code in the service processing the feed, where the stepBeforeElementMatch is being called:
  
  ```
          // Fire an 'onStepBeforeElementMatch' event
          if ($this->hasEventHandlers(self::EVENT_STEP_BEFORE_ELEMENT_MATCH)) {
              $event = new FeedProcessEvent([
                  'feed' => $feed,
                  'feedData' => $feedData,
                  'contentData' => $matchExistingElementData,
              ]);
  
              $this->trigger(self::EVENT_STEP_BEFORE_ELEMENT_MATCH, $event);
  
              if (!$event->isValid) {
                  return;
              }
  
              // Allow event to modify variables
              $feed = $event->feed;
              $feedData = $event->feedData;
              $matchExistingElementData = $event->contentData;
          }
  
  ```
  
  I have not tested this, but by the looks of it, it should be enough to set the `$event->isValid` to `false` in your code after doing the necessary checks that you want.
  
  Be aware that the `$event->feedData` you are working on is an array representation of your feed data (converted from, XML, JSON or whatever). So you need to do your checks accordingly. At this point, Feed Me has not tried to match against potentially existing elements in Craft. Your example code basically assumes there's a field in the feed element with the name `status` with the value `false`. If that's not the case, you could do your checks on whatever you want, before a certain date, etc.
  
  But if it is, something like this would be likely to work (again untested):
  
  ```
  if($event->feedData['status'] == "false") {
  
      $event->isValid = false;
  }
  
  ```
  
  If you're looking to skip based on some Craft element, you'd either need to query for it (basically doing some custom matching), or use an event later in the process (I can help you out there too, but maybe it's easier in your case to skip it already here).
  
  > **Comments:**
  > **username_0**: Thank you for your detailed answer, really appreciate it :)  
  > **username_1**: Happy to help, hope it worked out!  
  
  ---
  
  