How to get the entry id of the entry where field x is equal to y?

By: Leo Walker | Asked: 12/22/2024
ForumsCategory: Code HelpHow to get the entry id of the entry where field x is equal to y?
Leo Walker asked 20 hours ago
I struggling with how to construct the WHERE clause of FrmEntryMeta::getEntryIds or FrmEntry::getAll to return the entry(entries) where the value of field x is y when y is a number. The following will return all entries that contain a string of text  matching 'grizzly' in any of the fields: $entry_ids = FrmEntryMeta::getEntryIds(
   array(
      'fi.form_id' => 3,
     'meta_value LIKE' => 'grizzly',
   ),
);   But if I replace 'grizzly' with a number, no entries are returned.  And I need to find that number in a specific field on that form. Can someone explain how to structure the $where array to do this?
2 Answers
Rob LeVineRob LeVine answered 10 hours ago
Hi Leo, long time. I'm confused by a few things. 1. You have no 'field_id' parameter in the array, so how would it know what field to check? 2. If you want the value to be equal to 3 for example, why are you using LIKE instead of the equals sign? So something more like: array( 'fi.form_id' => 3, 'meta_value =' => 3, 'field_id' => 17 ), Alternatively you could use a straight sql command such as: select item_id from wp_frm_item_metas where field_id= 17 and meta_value = 3
Leo Walker answered 8 hours ago
Hi Rob, Great to hear from you, and thanks for replying. I tried your suggestion and it returns an empty array. I feel like there is a specific syntax to the $where parameter but I can't decipher or guess it. I've tried every variation I can think of, including: 'field_id' => 26 'field_id=' => 26 'fi.field_id' => 26 (what is the fi anyway??  it works on the form_id but I don't know why)   I can't find any documentation of this function and it's parameters (other than Mastermind's, which doesn't explain the $where parameter). I may have to resort to a direct db query. I avoid that as much as possible do to potential for breakage with future upgrades, but unless someone can advise on $where and $args syntax for this function, I may not have any other choice.
Victor Font replied 8 hours ago

In you case, I would do a direct DB lookup. You won't run into issues with future releases if you reference keys and use field_ids as variables.

Leo Walker replied 7 hours ago

Thank you, Victor. I'll Google around to remind myself how to do the query. I appreciate the direction.

Making the Best WordPress Plugin even better - Together

Take on bigger projects with confidence knowing you have access to an entire community of Formidable Experts and Professionals who have your back when the going gets tough. You got this!
Join the community
crossarrow-right