Advertisement
chrishajer

Use shortcode to display information from an entry

Aug 14th, 2013
241
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.75 KB | None | 0 0
  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');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement