daily pastebin goal
14%
SHARE
TWEET

Use shortcode to display information from an entry

chrishajer Aug 14th, 2013 107 Never
Upgrade to PRO!
ENDING IN00days00hours00mins00secs
 
  1. <?php
  2. // usage: [workshop form=17 field=1 value='Workshop A' return=2] using numeric IDs
  3. add_shortcode('workshop', 'total_attendees');
  4. function total_attendees($atts) {
  5.  
  6.         extract(shortcode_atts(array(
  7.             // set defaults
  8.             'form' => '403',
  9.             'field' => '1',
  10.             'value' => 'Workshop A',
  11.             'return' => '2',
  12.         ), $atts));
  13.  
  14.         // function to pull all the entries from one form
  15.         // get_leads($form_id, $sort_field_number=0, $sort_direction='DESC', $search='', $offset=0,
  16.         // $page_size=30, $star=null, $read=null, $is_numeric_sort = false, $start_date=null,
  17.         // $end_date=null, $status='active', $payment_status = false)
  18.         $attendees = RGFormsModel::get_leads($form, $return, 'ASC', '', 0, 999, NULL, NULL, FALSE, NULL, NULL, 'active', FALSE);
  19.  
  20.         // initialize an empty output string
  21.         $output = '<table width="100%">';
  22.  
  23.         // loop through all the returned results
  24.         foreach ($attendees as $attendee) {
  25.             // if the $value passed in matches the value stored in the field you passed in, add it to the output
  26.             if ($value == $attendee[$field]){
  27.                 $output .= '<tr><td width="35%">'. $attendee[$return] . '</td><td width="20%">Age: ' . $attendee['3'] . '</td><td width="45%">' . $attendee[$field] . '</td></tr>';
  28.             }
  29.         }
  30.  
  31.         // do some formatting and return the output from the shortcode
  32.         $output .= '</table>';
  33.  
  34.         // just the string above will be returned.
  35.         // You can style it here or where you are using the shortcode
  36.         return $output;
  37. }
  38. // needed for the above to process the guests list shortcode in sidebar widget
  39. add_filter('widget_text', 'do_shortcode');
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top