/** * Shortcode support for WP Posts and Pages * * @param array $tags An associative array of shortcode properties * @since 1.6.7 */ function pods_shortcode($tags) { $defaults = array('name' => null, 'id' => null, 'slug' => null, 'select' => null, 'order' => null, 'orderby' => null, 'limit' => null, 'where' => null, 'search' => true, 'page' => null, 'filters' => false, 'filters_label' => null, 'filters_location' => 'before', 'pagination' => false, 'pagination_label' => null, 'pagination_location' => 'after', 'col' => null, 'template' => null, 'helper' => null); $tags = shortcode_atts($defaults, $tags); $tags = apply_filters('pods_shortcode', $tags); if (empty($tags['name'])) { return '<e>Please provide a Pod name'; } if (empty($tags['template']) && empty($tags['col'])) { return '<e>Please provide either a template or column name'; } // id > slug (if both exist) $id = empty($tags['slug']) ? null : $tags['slug']; $id = empty($tags['id']) ? $id : absint($tags['id']); $pod = new Pod($tags['name'], $id); $found = 0; if (empty($id)) { $params = array(); if (0 < strlen($tags['order'])) { $params['orderby'] = $tags['order']; } if (0 < strlen($tags['orderby'])) { $params['orderby'] = $tags['orderby']; } if (!empty($tags['limit'])) { $params['limit'] = $tags['limit']; } if (0 < strlen($tags['where'])) { $params['where'] = $tags['where']; } if (0 < strlen($tags['select'])) { $params['select'] = $tags['select']; } if (empty($tags['search'])) { $params['search'] = false; } if (0 < absint($tags['page'])) { $params['page'] = absint($tags['page']); } $params = apply_filters('pods_shortcode_findrecords_params', $params); $pod->findRecords($params); $found = $pod->getTotalRows(); } elseif (!empty($tags['col'])) { $val = $pod->get_field($tags['col']); return empty($tags['helper']) ? $val : $pod->pod_helper($tags['helper'], $val); } ob_start(); if (empty($id) && false !== $tags['filters'] && 'before' == $tags['filters_location']) { echo $pod->getFilters($tags['filters'], $tags['filters_label']); } if (empty($id) && 0 < $found && false !== $tags['pagination'] && 'before' == $tags['pagination_location']) { echo $pod->getPagination($tags['pagination_label']); } echo $pod->showTemplate($tags['template']); if (empty($id) && 0 < $found && false !== $tags['pagination'] && 'after' == $tags['pagination_location']) { echo $pod->getPagination($tags['pagination_label']); } if (empty($id) && false !== $tags['filters'] && 'after' == $tags['filters_location']) { echo $pod->getFilters($tags['filters'], $tags['filters_label']); } return ob_get_clean(); }