Jump to content

Not able to delete a repeater item


SIERRA
 Share

Recommended Posts

Hi 

I am not able to delete a repeater item

This code works

$subscriptionpage = $pages->get(1442);

$subscription = $subscriptionpage->subscriptions->first(); // or whatever item you want to remove

echo $subscription;
$subscriptionpage->subscriptions->remove($subscription);
$subscriptionpage->of(false);
$subscriptionpage->save(); 

But this code does not works.

$subscriptionpage = $pages->get(1442);

$subscriptions=$subscriptionpage->subscriptions->find("email={email@mysite.com}");

echo $subscription;

$subscriptionpage->subscriptions->remove($subscription);
$subscriptionpage->of(false);
$subscriptionpage->save(); 

I checked the value of $subscriptions. Both has the same value. Could you please suggest. Thanks

 

Edited by SIERRA
Link to comment
Share on other sites

$subscriptions=$subscriptionpage->subscriptions->find("email={email@mysite.com}"); should be

$subscription=$subscriptionpage->subscriptions->find("email={email@mysite.com}");

Even then this is not working

Link to comment
Share on other sites

Well when you use "{email@mysite.com}" usually that means email@mysite.com is a variable. Such as "$email@mysite.com = 'tom@pw.com'". Obviously that wouldn't work. 

If you have a repeater that has a field email and the field has a value of 'email@mysite.com' then you need to use

$subscription = $subscriptionpage->subscriptions->find("email='email@mysite.com'");

As the string needs to be escaped. 

 

Edit: 

One thing that will help you is echoing $subscription wouldn't really work as it returns a PageArray. I would use echo $subscription->count as that will return if it found a match or not. If it's returning 0 that's why it will not delete anything. 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...