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 1 month 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 1 month 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 1 month 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 1 month 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 1 month ago

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

Leo Walker replied 4 weeks ago

All right, I'm still stuck. Can you please help me with the SELECT statement that will return the entry id of the entry whose value in field x is y? Seems simple but I'm not an SQL person. Thank for any help!

Victor Font replied 4 weeks ago

I'm sorry to hear you're having trouble writing your SQL. Unfortunately, SQL is specific to your environment. Wiriting the SQL statemeny for you requires access to you PHPMyAdmin. I do not work on people's sites without a paid project. If you'd like to hire me to write the code for you, please book an hour of my time here: https://bookme.name/vfconsulting/lite/formidable-forms-consultation

Leo Walker replied 4 weeks ago

Thanks, Victor. If I get stuck again, I'll reach out via your link. In the meantime, I have muddled my way through it.

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