Gideon So Posted November 24, 2023 Share Posted November 24, 2023 Hi all, Just come up to this need. Is it possible to find a page or pages by pagefile uploadName? Seems this is not working: $pages->find("file_field.uploadName%=sometext") Error: Exception: Property 'uploadName' not recognized in file_field Gideon Link to comment Share on other sites More sharing options...
da² Posted November 24, 2023 Share Posted November 24, 2023 Hello @Gideon So, This works: $pages->find('file_field.filedata.uploadName%=230925_213339_R.json'); 2 Link to comment Share on other sites More sharing options...
Gideon So Posted November 26, 2023 Author Share Posted November 26, 2023 i @da² Look like this only works when the page file field is set to single file. Gideon Link to comment Share on other sites More sharing options...
da² Posted November 26, 2023 Share Posted November 26, 2023 @Gideon So I did a test and it works on my side with multiple files, but there's something strange, the first uploaded file always has empty filedata. If I delete all files and upload again it's the same. ? That looks like a bug. Another way would be a hook to set filename into description field. Link to comment Share on other sites More sharing options...
Gideon So Posted November 26, 2023 Author Share Posted November 26, 2023 Hi @da² I don't know what is the difference between your settings and mine. The selector returns nothing at all even I set the file field to single file. Gideon Link to comment Share on other sites More sharing options...
da² Posted November 26, 2023 Share Posted November 26, 2023 Maybe PW version ? I use 3.0.228. Link to comment Share on other sites More sharing options...
Gideon So Posted November 26, 2023 Author Share Posted November 26, 2023 Hi @da² I am using 3.0.231. I will test again with 228. Gideon Link to comment Share on other sites More sharing options...
webdecker Posted November 29, 2023 Share Posted November 29, 2023 If I got it right, you are looking for pages having a (page)file (in field "file_field") named like something? Do you mean something like this...? $fieldname = 'file'; // or 'file_field' for your case...? $search = 'partofthename'; // V1 via api... $pgs = $pages->find("{$fieldname}%={$search}"); foreach ($pgs as $p) { echo "{$p->id} {$p->title}<br>\n"; } // V2 via database and api... $pgids = array_column( $this->database->query("select `pages_id` from `field_{$fieldname}` where `data` like '%" . addslashes($search) . "%'")->fetchAll(PDO::FETCH_OBJ), "pages_id" ); $pgs = $pages->find("id=" . ($pgids ? implode("|", $pgids) : "0")); foreach ($pgs as $p) { echo "{$p->id} {$p->title}<br>\n"; } Link to comment Share on other sites More sharing options...
Gideon So Posted November 30, 2023 Author Share Posted November 30, 2023 Hi @webdecker Thanks. I did it with the ProcessWire way. Gideon 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