Title: Displaying custom fields help
Last modified: August 22, 2016

---

# Displaying custom fields help

 *  [geohi](https://wordpress.org/support/users/geohi/)
 * (@geohi)
 * [11 years, 6 months ago](https://wordpress.org/support/topic/displaying-custom-fields-help/)
 * I have looked for the documentation but cannot find it.
 * We have a few custom fields and would like to display that data in the front-
   end overview table.
 * we looked at the displaycustomfieldstofrontend function, but are unable to figure
   out how to pull that data into the table for the specific ticket.
 * can you copy/paste the code i would use to enable this? thanks
 * [https://wordpress.org/plugins/wpsc-support-tickets/](https://wordpress.org/plugins/wpsc-support-tickets/)

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

 *  Plugin Author [jquindlen](https://wordpress.org/support/users/jquindlen/)
 * (@jquindlen)
 * [11 years, 6 months ago](https://wordpress.org/support/topic/displaying-custom-fields-help/#post-5482757)
 * You’ll want to copy the wpsctDisplayCustomFieldsToFrontend() function you mentioned
   and name it a new function that spits out the data you want, where you want it.
   Get rid of the table code inside the function, and use $specific_items[0] for
   the custom field name, and strip_tags(base64_decode($res[0][‘value’])) for the
   value.
 *  Thread Starter [geohi](https://wordpress.org/support/users/geohi/)
 * (@geohi)
 * [11 years, 6 months ago](https://wordpress.org/support/topic/displaying-custom-fields-help/#post-5482781)
 * Hmm.. ok. still having some issues. maybe you can help since youre the author
   🙂
 * Heres our new function:
 *     ```
       function wpsctDisplayCustomFieldsToFrontenda($primkey) {
           global $wpdb;
           // Custom fields
           $table_name33 = $wpdb->prefix . "wpstorecart_meta";
           $grabrecord = "SELECT * FROM <code>{$table_name33}</code> WHERE <code>type</code>='wpst-requiredinfo' ORDER BY <code>foreignkey</code> ASC;";
           $resultscf = $wpdb->get_results( $grabrecord , ARRAY_A );
           if(isset($resultscf)) {
                   echo '<table style="width:100%;"><tbody>';
                   foreach ($resultscf as $field) {
                       $specific_items = explode("||", $field['value']);
                       $res = $wpdb->get_results("SELECT * FROM <code>{$table_name33}</code> WHERE <code>type</code>='wpsct_custom_{$field['primkey']}' AND <code>foreignkey</code>='{$primkey}';", ARRAY_A);
                       if(@isset($res[0]['primkey'])) {
                           echo '<tr><td><p style="display:inline;color:red;font-weight:700;">'.$specific_items[0].':</p> '.strip_tags(base64_decode($res[0]['value'])).'</td></tr>';
                       }
                   }
                   echo '</tbody></table>';
           }
       }
       ```
   
 * and are using strip_tags(base64_decode($res[0][‘value’])) where want the data
   to be shown.
 * the database field is called “StatuteExpiry”
 * any suggestions?
 *  Plugin Author [jquindlen](https://wordpress.org/support/users/jquindlen/)
 * (@jquindlen)
 * [11 years, 6 months ago](https://wordpress.org/support/topic/displaying-custom-fields-help/#post-5482784)
 * if you’re only looking to display the field “StatuteExpiry” then change this 
   line:
 *     ```
       if(@isset($res[0]['primkey'])) {
       ```
   
 * to this
 *     ```
       if(@isset($res[0]['primkey']) && $specific_items[0]=="StatuteExpiry") {
       ```
   
 * the inside of that if statement should probably only echo the value like this:
 *     ```
       if(@isset($res[0]['primkey']) && $specific_items[0]=="StatuteExpiry") {
           echo strip_tags(base64_decode($res[0]['value']));
       }
       ```
   
 * or something like that. I haven’t tested this, but I think it should point you
   in the right direction. Let me know how it goes if you have any other questions.
 * EDIT: and get rid of the table code that is before and after the foreach loop.
 *  Thread Starter [geohi](https://wordpress.org/support/users/geohi/)
 * (@geohi)
 * [11 years, 6 months ago](https://wordpress.org/support/topic/displaying-custom-fields-help/#post-5482786)
 * you’re awesome… im going to give this a shot. one thing, however. the value of
   the custom field is actually `Statute Expires||optional||input (text)`
 * how should i write that out?
 * and im trying to see from the code how it will pull the data from that field 
   knowing all the primkeys and foreignkeys are subsequent?
 *  Thread Starter [geohi](https://wordpress.org/support/users/geohi/)
 * (@geohi)
 * [11 years, 6 months ago](https://wordpress.org/support/topic/displaying-custom-fields-help/#post-5482787)
 * Ok… here’s the whole function
 *     ```
       function wpsctDisplayCustomFieldsToFrontenda($primkey) {
   
           global $wpdb;
   
           // Custom fields
   
           $table_name33 = $wpdb->prefix . "wpstorecart_meta";
   
           $grabrecord = "SELECT * FROM <code>{$table_name33}</code> WHERE <code>type</code>='wpst-requiredinfo' ORDER BY <code>foreignkey</code> ASC;";
   
           $resultscf = $wpdb->get_results( $grabrecord , ARRAY_A );
   
           if(isset($resultscf)) {
   
                   foreach ($resultscf as $field) {
   
                       $specific_items = explode("||", $field['value']);
   
                       $res = $wpdb->get_results("SELECT * FROM <code>{$table_name33}</code> WHERE <code>type</code>='wpsct_custom_{$field['primkey']}' AND <code>foreignkey</code>='{$primkey}';", ARRAY_A);
   
                      if(@isset($res[0]['primkey']) && $specific_items[0]=="wpst-requiredinfo") {
           echo strip_tags(base64_decode($res[0]['value']));
       }
                   }
   
           }     
   
       }
       ```
   
 * and here’s how im trying to display it down below:
 * `base64_decode($res[0]['value'])`
 * but im still not getting anything to show. no errors though. which fieldname/
   value am i supposed to be using from the DB?
 *  Plugin Author [jquindlen](https://wordpress.org/support/users/jquindlen/)
 * (@jquindlen)
 * [11 years, 6 months ago](https://wordpress.org/support/topic/displaying-custom-fields-help/#post-5482788)
 * You’d be looking for “Statute Expires” in the code instead of “StatuteExpires”
   as I posted above. Like I said in the email you sent though, if you can help 
   me out on this dinner date, I’ll get this code done for you tomorrow 🙂 I’ll 
   still help you here regardless.
 *  Thread Starter [geohi](https://wordpress.org/support/users/geohi/)
 * (@geohi)
 * [11 years, 6 months ago](https://wordpress.org/support/topic/displaying-custom-fields-help/#post-5482790)
 * You’re awesome! So everything else looks correct other than “Statute Expires”?
 * I didn’t get an email back from you… Sure you sent it to the right address? I’d
   be glad to help any way I can, boss!

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

The topic ‘Displaying custom fields help’ is closed to new replies.

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

 * 7 replies
 * 2 participants
 * Last reply from: [geohi](https://wordpress.org/support/users/geohi/)
 * Last activity: [11 years, 6 months ago](https://wordpress.org/support/topic/displaying-custom-fields-help/#post-5482790)
 * Status: not a support question