Title: Retrieve custom submission data
Last modified: August 31, 2016

---

# Retrieve custom submission data

 *  [Paul Whitener Jr.](https://wordpress.org/support/users/pwhitene/)
 * (@pwhitene)
 * [10 years, 3 months ago](https://wordpress.org/support/topic/retrieve-custom-submission-data/)
 * I’m using Advanced Custom Fields to tie some custom data to user submissions.
   I’d like to display some of this data on the achievement page which pertains 
   to the submission. When a user is viewing an achievement, is there a function
   available to retrieve the ID of their submission for that achievement? Thanks!
 * [https://wordpress.org/plugins/badgeos/](https://wordpress.org/plugins/badgeos/)

Viewing 7 replies - 1 through 7 (of 7 total)

 *  [Michael Beckwith](https://wordpress.org/support/users/tw2113/)
 * (@tw2113)
 * The BenchPresser
 * [10 years, 3 months ago](https://wordpress.org/support/topic/retrieve-custom-submission-data/#post-7057080)
 * Hi Paul, thank you for your patience.
 * Can you let me know which way you’re showing the submissions on the frontend?
   I’m trying to track down the most appropriate spot to potentially filter for 
   this.
 * Also note that I believe only limited people can see a lot of the submissions
   on the frontend, based on who is set to be able to manage them. I don’t believe
   the submissions show like a standard single post or single post type.
 *  Thread Starter [Paul Whitener Jr.](https://wordpress.org/support/users/pwhitene/)
 * (@pwhitene)
 * [10 years, 3 months ago](https://wordpress.org/support/topic/retrieve-custom-submission-data/#post-7057082)
 * Hi Michael, thanks for the note. I have a small number of achievements, 8, that
   I have displayed manually on a page. Under each, I want to present the user some
   of the custom data that I’m using ACF to store with their submission. To retrieve
   this for a particular user, I need to be able to return the ID of the submission
   for that user tied to that achievement. In wp-admin, when viewing submissions,
   I see the ID for the achievement that the submission is tied to, I need to be
   able to do the opposite in my front-end template.
 * In this case, I’m not currently returning any of the default submission data,
   I just want the ID of the user’s submission tied to a particular achievement 
   so I can use ACF to query the custom data.
 * Does that help clarify?
 *  [Michael Beckwith](https://wordpress.org/support/users/tw2113/)
 * (@tw2113)
 * The BenchPresser
 * [10 years, 3 months ago](https://wordpress.org/support/topic/retrieve-custom-submission-data/#post-7057093)
 * Does help a fair amount. Looks like we don’t have any ready-made functionality
   for retrieving the submission ID though. So that begs the question of how comfortable
   are you with coding/customization? I could help construct a way to get that ID
   and whatnot, but it will involve some code and custom functions.
 *  Thread Starter [Paul Whitener Jr.](https://wordpress.org/support/users/pwhitene/)
 * (@pwhitene)
 * [10 years, 3 months ago](https://wordpress.org/support/topic/retrieve-custom-submission-data/#post-7057099)
 * Hi Michael, I’m very comfortable with custom functions. I regularly break into
   plugins and spin off custom versions of functions and shortcodes to better suit
   my needs. Let me know how I can help, your efforts are most appreciated.
 * Once wrapped up I’ll share this with the community, along with the ACF custom
   data tie-in I have set up, as there are some really powerful things you can do
   with this setup (for this example we’ve set up a grading scale for submissions,
   tied to a custom “assignment” achievement type, which is really useful for academic
   purposes).
 *  [Michael Beckwith](https://wordpress.org/support/users/tw2113/)
 * (@tw2113)
 * The BenchPresser
 * [10 years, 3 months ago](https://wordpress.org/support/topic/retrieve-custom-submission-data/#post-7057135)
 * This should help out. Pass in the post ID for the achievement, and it should 
   return the submission ID it’s associated with.
 *     ```
       function custom_get_submission_id_by_achievement_id( $post_id = 0 ) {
       	global $wpdb;
   
       	$query = "SELECT post_id
       			FROM $wpdb->postmeta
       			WHERE meta_key = '_badgeos_submission_achievement_id'
       			AND meta_value = '%s'
       			";
       	$prepared_query = $wpdb->prepare( $query, absint( $post_id ) );
       	$results = $wpdb->get_col( $prepared_query );
   
       	if ( !empty( $results ) ) {
       		return absint( $results[0] );
       	}
   
       	return '';
       }
       ```
   
 * Don’t forget to check for empty() in case it doesn’t find one, though it should.
 *  Thread Starter [Paul Whitener Jr.](https://wordpress.org/support/users/pwhitene/)
 * (@pwhitene)
 * [10 years, 2 months ago](https://wordpress.org/support/topic/retrieve-custom-submission-data/#post-7057162)
 * Hi Michael, this is really close. I have it set up and and I’m able to retrieve
   submission IDs tied to particular achievements. However, it’s not tied to particular
   users. Here’s an example:
 * I have an achievement (ID=344) and 2 subscribers, userA and userB. userA has 
   submitted an submission to achievement 344 but userB has not. Using the function
   above, when logged in as userA and I’m able to retrieve submission data as expected.
   However, userB is seeing the same data, even though they haven’t submitted anything
   to achievement 344 yet.
 * Is there a way to constrain this such that the submission ID returned is only
   for the logged in user’s ID?
 * Thanks!
 *  [Michael Beckwith](https://wordpress.org/support/users/tw2113/)
 * (@tw2113)
 * The BenchPresser
 * [10 years, 2 months ago](https://wordpress.org/support/topic/retrieve-custom-submission-data/#post-7057178)
 * Well, each submission is its own post in a post type. The only real way things
   are tied to the post type is by the fore-mentioned meta value. However, unless
   I’m mistaken, the submitting user is also listed as the author. So, with that,
   you have the ability to fetch the user who submitted a given submission, as well
   as the current user ID. I would recommend doing an if statement to compare those
   two values and only display something if they match OR the current user is an
   admin(like yourself).
 * Just some quick followup thoughts for you.

Viewing 7 replies - 1 through 7 (of 7 total)

The topic ‘Retrieve custom submission data’ is closed to new replies.

 * ![](https://s.w.org/plugins/geopattern-icon/badgeos_85d3bc.svg)
 * [BadgeOS](https://wordpress.org/plugins/badgeos/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/badgeos/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/badgeos/)
 * [Active Topics](https://wordpress.org/support/plugin/badgeos/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/badgeos/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/badgeos/reviews/)

## Tags

 * [submissions](https://wordpress.org/support/topic-tag/submissions/)

 * 7 replies
 * 2 participants
 * Last reply from: [Michael Beckwith](https://wordpress.org/support/users/tw2113/)
 * Last activity: [10 years, 2 months ago](https://wordpress.org/support/topic/retrieve-custom-submission-data/#post-7057178)
 * Status: not resolved