Using entry data in php shortcode

By: Theo Lee | Asked: 09/20/2022
ForumsCategory: General questionsUsing entry data in php shortcode
Theo Lee asked 2 years ago
I have a Formidable Form View which uses the key in the URL to filter the view. ?resultskey=[key sanitize_url=1]
I want to create a shortcode which pulls values from the specific entry key. Is it possible to use the values from the key (as set in the URL) in a php file?  
3 Answers
Rob LeVineRob LeVine answered 2 years ago

Sure. You can do this:

$entry_id = FrmEntry::get_id_by_key($entry_key);
$entry = FrmEntry::getOne( $entry_id );

and then "$entry" will contain all the information

Theo Lee answered 2 years ago
Thanks @Rob LeVine  I tried the following in a shortcode but all I got was "There has been a critical error on this website." $entry_id = FrmEntry::get_id_by_key($entry_key) $entry = FrmEntry::getOne( $entry_id ); echo $entry;  
Rob LeVineRob LeVine replied 2 years ago

Turn on your error display (or look in your log file) to see what the full error is. That code is fine as is, though you have to set $entry_key at some point. Generally that means some sort of syntax error. Also, you'll want to do print_r($entry) or since it's an array of info.

Theo Lee answered 2 years ago
Thanks @Rob LeVine  I got
PHP Parse error:  syntax error, unexpected '$entry' (T_VARIABLE) 
  How do I 'set' $entry_key ? Would it not be taken from the parameter in the ULR resultskey?
Rob LeVineRob LeVine replied 2 years ago

Ha! The error is because of the missing semicolon (;) at the end of the first line. I edited my previous response.

The value that you put into #entry_key can come from the URL via the $_REQUEST global variable or it can be passed in via the shortcode invocation, whichever works better for you.

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