I’ve got a quiz that users fill out on wordpress using the plugin FSQM Pro and when they submit it they are redirected to a page that will display some text along with their answer to a question in the quiz. To recall the answer they submit, I have used this code:
<?php
global $wpdb, $ipt_fsqm_info;
$form_id = 9;
$data_ids = $wpdb->get_col( $wpdb->prepare( "SELECT id FROM {$ipt_fsqm_info['data_table']} WHERE form_id = %d ORDER BY id DESC LIMIT 0,1", $form_id ) );
foreach ( $data_ids as $data_id ) {
$data = new IPT_FSQM_Form_Elements_Data( $data_id );
echo wpautop( $data->data->pinfo[14]['value'] );
}
?>
However when I execute it, it returns the most recent value regardless of user. How would I get it to only return the most recent value of the current user?
----------Update----------
After a lot of tinkering it is now working. The correct code is as follows
<?php
global $wpdb, $ipt_fsqm_info, $user_ID;
get_currentuserinfo();
$form_id = 9;
$data_ids = $wpdb->get_col( $wpdb->prepare( "SELECT id
FROM {$ipt_fsqm_info['data_table']}
WHERE form_id = %d
AND user_id = %d
ORDER BY id DESC LIMIT 0,1", $form_id, $user_ID ) );
foreach ( $data_ids as $data_id ) {
$data = new IPT_FSQM_Form_Elements_Data( $data_id );
echo wpautop( $data->data->pinfo[14]['value'] );
}
?>
Massive thank you's to everyone that gave their time to helping me with this.