PWaddict Posted November 10, 2015 Posted November 10, 2015 Hello, I would like to check if a specific field has 0 value in ALL children of the current page and then echo for example: Sold Out. Can you help me? Thanks in advance!
tpr Posted November 10, 2015 Posted November 10, 2015 Something like this? if(count($page->children('my_field=0')) == 0) { echo "Sold out"; }
Soma Posted November 10, 2015 Posted November 10, 2015 Or little more efficent if(!$pages->count("parent=$page, my_field=0")) { echo "Sold out"; } 2
PWaddict Posted November 10, 2015 Author Posted November 10, 2015 Something like this? if(count($page->children('my_field=0')) == 0) { echo "Sold out"; } Did you edit it? The first one you posted which I got in my email is working perfectly: if(count($pages->get("$page->id")->children("my_field=0"))) { echo "Sold out"; } Thank you guys both for the help!
kongondo Posted November 10, 2015 Posted November 10, 2015 You really want to use $pages->count. count($page...) will come back and bite you when you have lots of pages... 3
tpr Posted November 10, 2015 Posted November 10, 2015 Did you edit it? The first one you posted which I got in my email is working perfectly: if(count($pages->get("$page->id")->children("my_field=0"))) { echo "Sold out"; } Yes, I noticed that you mentioned "current page" so I thought there's no need to use get(). @kongondo Thanks, I always suspected this but never really dived into it 1
PWaddict Posted November 10, 2015 Author Posted November 10, 2015 You really want to use $pages->count. count($page...) will come back and bite you when you have lots of pages... The maximum children will be about 6.
kongondo Posted November 10, 2015 Posted November 10, 2015 Yes, I noticed that you mentioned "current page" so I thought there's no need to use get(). @kongondo Thanks, I always suspected this but never really dived into it I have been bitten several times... (Blog Module)
PWaddict Posted November 10, 2015 Author Posted November 10, 2015 You really want to use $pages->count. count($page...) will come back and bite you when you have lots of pages... I used the Soma's version just to be safe. Thanks.
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now