PWaddict Posted November 10, 2015 Share 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! Link to comment Share on other sites More sharing options...
tpr Posted November 10, 2015 Share Posted November 10, 2015 Something like this? if(count($page->children('my_field=0')) == 0) { echo "Sold out"; } Link to comment Share on other sites More sharing options...
Soma Posted November 10, 2015 Share Posted November 10, 2015 Or little more efficent if(!$pages->count("parent=$page, my_field=0")) { echo "Sold out"; } 2 Link to comment Share on other sites More sharing options...
PWaddict Posted November 10, 2015 Author Share 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! Link to comment Share on other sites More sharing options...
kongondo Posted November 10, 2015 Share 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 Link to comment Share on other sites More sharing options...
tpr Posted November 10, 2015 Share 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 Link to comment Share on other sites More sharing options...
PWaddict Posted November 10, 2015 Author Share 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. Link to comment Share on other sites More sharing options...
kongondo Posted November 10, 2015 Share 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) Link to comment Share on other sites More sharing options...
PWaddict Posted November 10, 2015 Author Share 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. Link to comment Share on other sites More sharing options...
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