wbmnfktr Posted February 23, 2022 Share Posted February 23, 2022 $restaurants = $pages->findRaw("template=restaurant", ['id', 'title', 'modified']); $json = json_encode(['restaurants' => array_values($restaurants)]); Moved this from here - to keep the other thread clean: So... yeah that little script does a really good job. While I read about findRaw() somewhere I never really cared somehow. Maybe because I haven't looked that deep into it. It does an amazing job but for a ready to use JSON feed in an external site/app/ssg parts are missing - for me. Text and textarea fields are fine and easy to use somewhere else. PageReferences are slightly different and need a slightly different subfield request with, otherwise you would just receive the IDs:'myPageReferenceFieldMultiple.title' "myPageReferenceFieldMultiple": { "7009": { "title": "Voucher" }, "7010": { "title": "Dinner" }, "7011": { "title": "Outdoor" }, "7012": { "title": "Vegan offers" }, "7013": { "title": "Take away" }, "8574": { "title": "Special offers" } }, Image fields really only have the raw data. No url, no image details, nothing. "myImageFieldSingle": [ { "data": "logo.png", "sort": "0", "description": "", "modified": "2020-04-16 18:59:33", "created": "2020-04-16 18:59:33", "filedata": "", "filesize": null, "created_users_id": "0", "modified_users_id": "0", "width": null, "height": null, "ratio": null } ], And repeater matrix fields are yet another animal. Similar to repeater fields but more complicated to get each and every matrix entry and its details. "myRepeaterMatrixField": { "data": "8577,7060,7360,6443,6415,6414", "count": "6", "parent_id": "6399" } Amazing... so far. Ping at @bernhard @kongondo 1 Link to comment Share on other sites More sharing options...
kongondo Posted February 23, 2022 Share Posted February 23, 2022 (edited) 1 hour ago, wbmnfktr said: PageReferences are slightly different and need a slightly different subfield request with, otherwise you would just receive the IDs:'myPageReferenceFieldMultiple.title' Yes. There are these alternatives though: Quote // You can also use this format below to get multiple subfields from one field: $a = $pages->findRaw("template=blog", [ "title", "categories" => [ "id", "title" ] ]); ☝️this has never worked for me though. Will at best return an empty array and at worst throw a SQL error. 1 hour ago, wbmnfktr said: Image fields really only have the raw data. No url, no image details, nothing. Works fine for me, except for URL. I get ratio, width, etc. https://processwire.com/api/ref/pages/find-raw/ Edited February 23, 2022 by kongondo Link to comment Share on other sites More sharing options...
wbmnfktr Posted February 23, 2022 Author Share Posted February 23, 2022 18 minutes ago, kongondo said: ☝️this has never worked for me though. Will at best return an empty array and at worst throw a SQL error. It's the same here. 18 minutes ago, kongondo said: Works fine for me, except for URL. I get ratio, width, etc. Oh... that's interesting. I tried my query on all of my pages and... some now return details, yet I don't know what's happening. It didn't bother me in the past so I just might ignore it for the moment. 20 minutes ago, kongondo said: https://processwire.com/api/ref/pages/find-raw/ That's were I was looking right now. 1 Link to comment Share on other sites More sharing options...
bernhard Posted February 23, 2022 Share Posted February 23, 2022 Well... what you are discovering is exactly why I built RockFinder. The first version was built before findRaw existed but I'm still using the current version RockFinder3 for RockGrid because it does all the things you mentioned properly with an easy to use syntax. Link to comment Share on other sites More sharing options...
wbmnfktr Posted February 23, 2022 Author Share Posted February 23, 2022 So maybe I have to play with RockFinder3 a bit even before trying AppApi. To be honest I would never ever have thought about using it just because it feels way overhead for "just a JSON feed". So... I will cherry-pick in that docs and maybe find a way to get the results I need. Link to comment Share on other sites More sharing options...
bernhard Posted February 23, 2022 Share Posted February 23, 2022 Or you use RockHeadless ? Referencing to the other post... 2 Link to comment Share on other sites More sharing options...
adrian Posted February 24, 2022 Share Posted February 24, 2022 8 hours ago, kongondo said: ☝️this has never worked for me though. Will at best return an empty array and at worst throw a SQL error. Is this the issue? https://github.com/processwire/processwire-issues/issues/1511 - if so, it is fixed now. Link to comment Share on other sites More sharing options...
adrian Posted February 24, 2022 Share Posted February 24, 2022 Have you guys tried combining findRaw() with url hooks - https://processwire.com/blog/posts/pw-3.0.173/ ? I find it a really easy way to take care of this stuff. 2 Link to comment Share on other sites More sharing options...
kongondo Posted February 24, 2022 Share Posted February 24, 2022 5 hours ago, adrian said: Have you guys tried combining findRaw() with url hooks - https://processwire.com/blog/posts/pw-3.0.173/ ? I find it a really easy way to take care of this stuff. Yep. Padloper2 ?. 1 Link to comment Share on other sites More sharing options...
kongondo Posted February 24, 2022 Share Posted February 24, 2022 5 hours ago, adrian said: Is this the issue? https://github.com/processwire/processwire-issues/issues/1511 - if so, it is fixed now. Quite likely. Link to comment Share on other sites More sharing options...
wbmnfktr Posted February 24, 2022 Author Share Posted February 24, 2022 It works in 3.0.194. Good tip! 1 Link to comment Share on other sites More sharing options...
rick Posted February 27, 2022 Share Posted February 27, 2022 Just tossin' more info in the thread... https://github.com/salsify/jsonstreamingparser https://www.jsonfeed.org/version/1.1/ 1 Link to comment Share on other sites More sharing options...
elabx Posted February 28, 2022 Share Posted February 28, 2022 Just stumbled into this package and reminded me of this discussion, thought it might be worth dumping it here, maybe the goals it means to solve resonate with the ideas exchanged here: https://fractal.thephpleague.com/ 2 Link to comment Share on other sites More sharing options...
Recommended Posts