?> <div class="container"> <div class="row"> <?php $posts_per_page = 6; $args = array('post_type' => 'book', 'posts_per_page' => $posts_per_page, 'order' => asc); $loop = new WP_Query($args); var_dump(get_post_meta($post->ID)); if ($loop->have_posts()) { while ($loop->have_posts()) { $loop->the_post(); $id = get_the_ID(); $book_title = get_post_meta($id, 'book_title', true); $book_publication = get_post_meta($id, 'publication_date', true); $book_cover = pods_image_url(get_post_meta($id, 'book_cover', true), null); ?> <div class="col-md-4 book-wrap"> <div style="position: relative;" class="bg-shadow"> <img class="img-responsive" src="<?php echo $book_cover; ?> "/> <div class="book book-title"><a href="<?php echo the_permalink(); ?> "><?php echo $book_title; ?> </a></div> <div class="book book-desc">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Fusce non sagittis metus. In in vehicula neque. Morbi nibh nisi, vestibulum sit amet diam vitae, convallis porttitor leo.</div>
<article> <header class="entry-header"> <h1 class="entry-title"><?php _e('User Profile', 'twentytwelve'); ?> </h1> </header> <div class="author-info"> <h2><?php echo $name; ?> </h1> <div class="author-avatar"> <?php echo '<a href="' . pods_image_url($user->picture, 'large') . '">' . pods_image($user->picture, 'thumbnail') . '</a>'; ?> </div><!-- .author-avatar --> <div class="author-description"> <p><strong><?php _e('Email:', 'twentytwelve'); ?> </strong> <?php echo '<a href="mailto:' . $email . '">' . $email . '</a>'; ?> </p> <p><strong><?php _e('Phone:', 'twentytwelve'); ?> </strong> <?php echo $phone;
<div class="row span16" id="featured-story-two"> <div class="span6"></div> <div class="span6 spancontent"> <h1 class="light lgrey"><?php echo $story->display('title'); ?> </h3> <h1 class="dgrey large"><?php echo $story->display('subtitle'); ?> </h3> <p><?php echo $story->display('excerpt'); ?> </p> <a href="<?php echo $link; ?> " class="button-blue-dark">Learn More</a> </div> </div> <style type="text/css"> #featured-story-two { background: url(<?php echo pods_image_url(get_post_meta($story->field('ID'), 'image', true), 'original'); ?> ) no-repeat; } </style> <?php }
/** * * Generate UI for Data Management * * @param mixed $options Array or String containing Pod or Options to be used * @param bool $amend Whether to amend the default UI options or replace entirely * * @return PodsUI|void UI object or void if custom UI used * * @since 2.3.10 */ public function ui($options = null, $amend = false) { $num = ''; if (empty($options)) { $options = array(); } else { $num = pods_var('num', $options, ''); if (empty($num)) { $num = ''; } } if ($this->id() != pods_var('id' . $num, 'get', null, null, true)) { $this->fetch(pods_var('id' . $num, 'get', null, null, true)); } if (!empty($options) && !$amend) { $this->ui = $options; return pods_ui($this); } elseif (!empty($options) || 'custom' != pods_var('ui_style', $this->pod_data['options'], 'post_type', null, true)) { $actions_enabled = pods_var_raw('ui_actions_enabled', $this->pod_data['options']); if (!empty($actions_enabled)) { $actions_enabled = (array) $actions_enabled; } else { $actions_enabled = array(); } $available_actions = array('add', 'edit', 'duplicate', 'delete', 'reorder', 'export'); if (!empty($actions_enabled)) { $actions_disabled = array('view' => 'view'); foreach ($available_actions as $action) { if (!in_array($action, $actions_enabled)) { $actions_disabled[$action] = $action; } } } else { $actions_disabled = array('duplicate' => 'duplicate', 'view' => 'view', 'export' => 'export'); if (1 == pods_var('ui_export', $this->pod_data['options'], 0)) { unset($actions_disabled['export']); } } if (empty($options)) { $author_restrict = false; if (isset($this->fields['author']) && 'pick' == $this->fields['author']['type'] && 'user' == $this->fields['author']['pick_object']) { $author_restrict = 'author.ID'; } if (!pods_is_admin(array('pods', 'pods_content'))) { if (!current_user_can('pods_add_' . $this->pod)) { $actions_disabled['add'] = 'add'; if ('add' == pods_var('action' . $num, 'get')) { $_GET['action' . $num] = 'manage'; } } if (!$author_restrict && !current_user_can('pods_edit_' . $this->pod) && !current_user_can('pods_edit_others_' . $this->pod)) { $actions_disabled['edit'] = 'edit'; } if (!$author_restrict && !current_user_can('pods_delete_' . $this->pod) && !current_user_can('pods_delete_others_' . $this->pod)) { $actions_disabled['delete'] = 'delete'; } if (!current_user_can('pods_reorder_' . $this->pod)) { $actions_disabled['reorder'] = 'reorder'; } if (!current_user_can('pods_export_' . $this->pod)) { $actions_disabled['export'] = 'export'; } } } $_GET['action' . $num] = pods_var('action' . $num, 'get', pods_var('action', $options, 'manage')); $index = $this->pod_data['field_id']; $label = __('ID', 'pods'); if (isset($this->pod_data['fields'][$this->pod_data['field_index']])) { $index = $this->pod_data['field_index']; $label = $this->pod_data['fields'][$this->pod_data['field_index']]; } $manage = array($index => $label); if (isset($this->pod_data['fields']['modified'])) { $manage['modified'] = $this->pod_data['fields']['modified']['label']; } $manage_fields = pods_var_raw('ui_fields_manage', $this->pod_data['options']); if (!empty($manage_fields)) { $manage_new = array(); foreach ($manage_fields as $manage_field) { if (isset($this->pod_data['fields'][$manage_field])) { $manage_new[$manage_field] = $this->pod_data['fields'][$manage_field]; } elseif (isset($this->pod_data['object_fields'][$manage_field])) { $manage_new[$manage_field] = $this->pod_data['object_fields'][$manage_field]; } elseif ($manage_field == $this->pod_data['field_id']) { $field = array('name' => $manage_field, 'label' => 'ID', 'type' => 'number', 'width' => '8%'); $manage_new[$manage_field] = PodsForm::field_setup($field, null, $field['type']); } } if (!empty($manage_new)) { $manage = $manage_new; } } $manage = apply_filters('pods_admin_ui_fields_' . $this->pod, apply_filters('pods_admin_ui_fields', $manage, $this->pod, $this), $this->pod, $this); $icon = pods_var_raw('ui_icon', $this->pod_data['options']); if (!empty($icon)) { $icon = pods_image_url($icon, '32x32'); } $filters = pods_var_raw('ui_filters', $this->pod_data['options']); if (!empty($filters)) { $filters_new = array(); foreach ($filters as $filter_field) { if (isset($this->pod_data['fields'][$filter_field])) { $filters_new[$filter_field] = $this->pod_data['fields'][$filter_field]; } elseif (isset($this->pod_data['object_fields'][$filter_field])) { $filters_new[$filter_field] = $this->pod_data['object_fields'][$filter_field]; } } $filters = $filters_new; } $ui = array('fields' => array('manage' => $manage, 'add' => $this->pod_data['fields'], 'edit' => $this->pod_data['fields'], 'duplicate' => $this->pod_data['fields']), 'icon' => $icon, 'actions_disabled' => $actions_disabled); if (!empty($filters)) { $ui['fields']['search'] = $filters; $ui['filters'] = array_keys($filters); $ui['filters_enhanced'] = true; } $reorder_field = pods_var_raw('ui_reorder_field', $this->pod_data['options']); if (in_array('reorder', $actions_enabled) && !in_array('reorder', $actions_disabled) && !empty($reorder_field) && (!empty($this->pod_data['object_fields']) && isset($this->pod_data['object_fields'][$reorder_field]) || isset($this->pod_data['fields'][$reorder_field]))) { $ui['reorder'] = array('on' => $reorder_field); $ui['orderby'] = $reorder_field; $ui['orderby_dir'] = 'ASC'; } if (!empty($author_restrict)) { $ui['restrict'] = array('author_restrict' => $author_restrict); } if (!in_array('delete', $ui['actions_disabled'])) { $ui['actions_bulk'] = array('delete' => array('label' => __('Delete', 'pods'))); } $detail_url = pods_var('detail_url', $this->pod_data['options']); if (0 < strlen($detail_url)) { $ui['actions_custom'] = array('view_url' => array('label' => 'View', 'link' => get_site_url() . '/' . $detail_url)); } // @todo Customize the Add New / Manage links to point to their correct menu items $ui = apply_filters('pods_admin_ui_' . $this->pod, apply_filters('pods_admin_ui', $ui, $this->pod, $this), $this->pod, $this); // Override UI options foreach ($options as $option => $value) { $ui[$option] = $value; } $this->ui = $ui; return pods_ui($this); } do_action('pods_admin_ui_custom', $this); do_action('pods_admin_ui_custom_' . $this->pod, $this); }
function pods_user_profile_display($user) { //Escape all of the meta data we need into variables $name = esc_attr($user->user_firstname) . ' ' . esc_attr($user->user_lastname); $title = esc_attr($user->title); $email = esc_attr($user->user_email); $phone = esc_attr($user->phone_number); $street_1 = esc_attr($user->street_address_line_1); $street_2 = esc_attr($user->street_address_line_2); $city = esc_attr($user->city); $state = esc_attr($user->state); $zip = esc_attr($user->zip_code); $website = esc_url($user->user_url); $twitter = esc_url($user->twitter); $linkedin = esc_url($user->linkedin); ?> <div class="author-info"> <h2><?php echo $name; ?> </h1> <div class="author-avatar"> <?php echo '<a href="' . pods_image_url($user->picture, 'large') . '">' . pods_image($user->picture, 'thumbnail') . '</a>'; ?> </div><!-- .author-avatar --> <div class="author-description"> <p><strong><?php _e('Email:', 'twentytwelve'); ?> </strong> <?php echo '<a href="mailto:' . $email . '">' . $email . '</a>'; ?> </p> <p><strong><?php _e('Phone:', 'twentytwelve'); ?> </strong> <?php echo $phone; ?> </p> <div><p><strong><?php _e('Address:', 'twentytwelve'); ?> </strong></p> <?php echo '<p>' . $street_1 . '</p>' . '<p>' . $street_2 . '</p>' . '<p>' . $city . ', ' . $state . ' ' . $zip . '</p>'; ?> </div> <p><strong><?php _e('Website:', 'twentytwelve'); ?> </strong> <?php echo '<a href="' . $website . '">' . $website . '</a>'; ?> </p> <p><strong><?php _e('Twitter:', 'twentytwelve'); ?> </strong> <?php echo '<a href="' . $twitter . '">' . $twitter . '</a>'; ?> </p> <p><strong><?php _e('LinkedIn:', 'twentytwelve'); ?> </strong> <?php echo '<a href="' . $linkedin . '">' . $linkedin . '</a>'; ?> </p> </div><!-- .author-description --> </div><!-- .author-info --> <?php }
<?php // Example 1: Using pods_image_url as shortcut $pods = pods('books', 300); // Put the entire array of an image field into a variable $imgfield = $pods->field('image'); // Use var to get the image URL. $imgurl = pods_image_url($imgfield); // Outputs image to web page echo '<img src="' . $imgurl . '">'; // Example 2: Drilling down array to image ID and outputting with a WordPress function // Create a new object for Books with an ID of 300 $pods = pods('books', 300); // Put the entire array of an image field into a variable $imgfield = $pods->field('image'); // Assign a variable to image field ID key $imgID = $imgfield[ID]; // Display image using the ID stored in $imgID echo wp_get_attachment_image($imgID);
/** * Create PodsUI content for the administration pages */ public function admin_content() { $pod_name = str_replace(array('pods-manage-', 'pods-add-new-'), '', $_GET['page']); $pod = pods($pod_name, pods_var('id', 'get', null, null, true)); $default = 'manage'; if (false !== strpos($_GET['page'], 'pods-add-new-')) { $default = 'add'; } $actions_enabled = pods_var_raw('ui_actions_enabled', $pod->pod_data['options']); if (!empty($actions_enabled)) { $actions_enabled = (array) $actions_enabled; } else { $actions_enabled = array(); } $available_actions = array('add', 'edit', 'duplicate', 'delete', 'reorder', 'export'); if (!empty($actions_enabled)) { $actions_disabled = array('view' => 'view'); foreach ($available_actions as $action) { if (!in_array($action, $actions_enabled)) { $actions_disabled[$action] = $action; } } } else { $actions_disabled = array('duplicate' => 'duplicate', 'view' => 'view', 'export' => 'export'); if (1 == pods_var('ui_export', $pod->pod_data['options'], 0)) { unset($actions_disabled['export']); } } $author_restrict = false; if (isset($pod->fields['author']) && 'pick' == $pod->fields['author']['type'] && 'user' == $pod->fields['author']['pick_object']) { $author_restrict = 'author.ID'; } if (!pods_is_admin(array('pods', 'pods_content'))) { if (!current_user_can('pods_add_' . $pod_name)) { $actions_disabled['add'] = 'add'; $default = 'manage'; } if (!$author_restrict && !current_user_can('pods_edit_' . $pod_name) && !current_user_can('pods_edit_others_' . $pod_name)) { $actions_disabled['edit'] = 'edit'; } if (!$author_restrict && !current_user_can('pods_delete_' . $pod_name) && !current_user_can('pods_delete_others_' . $pod_name)) { $actions_disabled['delete'] = 'delete'; } if (!current_user_can('pods_reorder_' . $pod_name)) { $actions_disabled['reorder'] = 'reorder'; } if (!current_user_can('pods_export_' . $pod_name)) { $actions_disabled['export'] = 'export'; } } $_GET['action'] = pods_var('action', 'get', $default); $index = $pod->pod_data['field_id']; $label = __('ID', 'pods'); if (isset($pod->pod_data['fields'][$pod->pod_data['field_index']])) { $index = $pod->pod_data['field_index']; $label = $pod->pod_data['fields'][$pod->pod_data['field_index']]; } $manage = array($index => $label); if (isset($pod->pod_data['fields']['modified'])) { $manage['modified'] = $pod->pod_data['fields']['modified']['label']; } $manage_fields = pods_var_raw('ui_fields_manage', $pod->pod_data['options']); if (!empty($manage_fields)) { $manage_new = array(); foreach ($manage_fields as $manage_field) { if (isset($pod->pod_data['fields'][$manage_field])) { $manage_new[$manage_field] = $pod->pod_data['fields'][$manage_field]; } elseif (isset($pod->pod_data['object_fields'][$manage_field])) { $manage_new[$manage_field] = $pod->pod_data['object_fields'][$manage_field]; } elseif ($manage_field == $pod->pod_data['field_id']) { $field = array('name' => $manage_field, 'label' => 'ID', 'type' => 'number', 'width' => '8%'); $manage_new[$manage_field] = PodsForm::field_setup($field, null, $field['type']); } } if (!empty($manage_new)) { $manage = $manage_new; } } $manage = apply_filters('pods_admin_ui_fields_' . $pod->pod, apply_filters('pods_admin_ui_fields', $manage, $pod->pod, $pod), $pod->pod, $pod); $icon = pods_var_raw('ui_icon', $pod->pod_data['options']); if (!empty($icon)) { $icon = pods_image_url($icon, '32x32'); } $filters = pods_var_raw('ui_filters', $pod->pod_data['options']); if (!empty($filters)) { $filters_new = array(); foreach ($filters as $filter_field) { if (isset($pod->pod_data['fields'][$filter_field])) { $filters_new[$filter_field] = $pod->pod_data['fields'][$filter_field]; } elseif (isset($pod->pod_data['object_fields'][$filter_field])) { $filters_new[$filter_field] = $pod->pod_data['object_fields'][$filter_field]; } } $filters = $filters_new; } $ui = array('pod' => $pod, 'fields' => array('manage' => $manage, 'add' => $pod->pod_data['fields'], 'edit' => $pod->pod_data['fields'], 'duplicate' => $pod->pod_data['fields']), 'icon' => $icon, 'actions_disabled' => $actions_disabled); if (!empty($filters)) { $ui['fields']['search'] = $filters; $ui['filters'] = array_keys($filters); $ui['filters_enhanced'] = true; } $reorder_field = pods_var_raw('ui_reorder_field', $pod->pod_data['options']); if (in_array('reorder', $actions_enabled) && !in_array('reorder', $actions_disabled) && !empty($reorder_field) && (!empty($pod->pod_data['object_fields']) && isset($pod->pod_data['object_fields'][$reorder_field]) || isset($pod->pod_data['fields'][$reorder_field]))) { $ui['reorder'] = array('on' => $reorder_field); $ui['orderby'] = $reorder_field; $ui['orderby_dir'] = 'ASC'; } if (!empty($author_restrict)) { $ui['restrict'] = array('author_restrict' => $author_restrict); } if (!in_array('delete', $ui['actions_disabled'])) { $ui['actions_bulk'] = array('delete' => array('label' => __('Delete', 'pods'))); } if (strlen(pods_var('detail_url', $pod->pod_data)) < 1) { $ui['actions_custom'] = array('view_url' => array('label' => 'View', 'link' => get_site_url() . '/' . pods_var('detail_url', $pod->pod_data['options']))); } // @todo Customize the Add New / Manage links to point to their correct menu items $ui = apply_filters('pods_admin_ui_' . $pod->pod, apply_filters('pods_admin_ui', $ui, $pod->pod, $pod), $pod->pod, $pod); pods_ui($ui); }
get_header(); $options = get_option('wpt_settings'); if (isset($options['display_comments']) && $options['display_comments'] == true) { $display = 'style="display: block;"'; } else { $display = 'style="display: none;"'; } $arg = array('post_type' => 'book', 'id' => get_the_ID()); $loop = new WP_Query($arg); if ($loop->have_posts()) { $loop->the_post(); $title = get_the_title(); $upper_title = strtoupper($title); $book = get_post_meta(get_the_ID()); $book_cover = pods_image_url($book['book_cover'][0], null); $date = new DateTime($book['publication_date'][0]); $formatted_date = date_format($date, 'm-d-Y'); var_dump($formatted_date); ?> <div class="container bg-shadow"> <div class="row"> <div class="col-sm-9"> <div class="post-meta"> <h2><?php echo $upper_title; ?> </h2> <div class="post-meta-bar cf"> <div class="post-meta-date">
/** * Return the value for a field. * * If you are getting a field for output in a theme, most of the time you will want to use display() instead. * * This function will return arrays for relationship and file fields. * * @param string|array $name The field name, or an associative array of parameters * @param boolean $single (optional) For tableless fields, to return the whole array or the just the first item * @param boolean $raw (optional) Whether to return the raw value, or to run through the field type's display method * * @return mixed|null Value returned depends on the field type, null if the field doesn't exist, false if no value returned for tableless fields * @since 2.0 * @link http://pods.io/docs/field/ */ public function field($name, $single = null, $raw = false) { global $sitepress; $defaults = array('name' => $name, 'orderby' => null, 'single' => $single, 'params' => null, 'in_form' => false, 'raw' => $raw, 'raw_display' => false, 'display' => false, 'get_meta' => false, 'output' => null, 'deprecated' => false, 'args' => array()); if (is_array($name) || is_object($name)) { $params = (object) array_merge($defaults, (array) $name); } else { $params = (object) $defaults; } if (null === $params->output) { $params->output = $this->do_hook('field_related_output_type', 'arrays', $this->row, $params); } // Support old $orderby variable if (null !== $params->single && is_string($params->single) && empty($params->orderby)) { pods_deprecated('Pods::field', '2.0', 'Use $params[ \'orderby\' ] instead'); $params->orderby = $params->single; $params->single = false; } if (null !== $params->single) { $params->single = (bool) $params->single; } if (is_array($params->name) || strlen(trim($params->name)) < 1) { return null; } $params->name = trim($params->name); $value = null; if (isset($this->row_override[$params->name])) { $value = $this->row_override[$params->name]; } if (false === $this->row()) { if (false !== $this->data()) { $this->fetch(); } else { return $value; } } if ($this->data->field_id == $params->name) { if (isset($this->row[$params->name])) { return $this->row[$params->name]; } elseif (null !== $value) { return $value; } return 0; } $tableless_field_types = PodsForm::tableless_field_types(); $simple_tableless_objects = PodsForm::field_method('pick', 'simple_objects'); $params->traverse = array(); if (in_array($params->name, array('_link', 'detail_url')) || in_array($params->name, array('permalink', 'the_permalink')) && in_array($this->pod_data['type'], array('post_type', 'media'))) { if (0 < strlen($this->detail_page)) { $value = get_home_url() . '/' . $this->do_magic_tags($this->detail_page); } elseif (in_array($this->pod_data['type'], array('post_type', 'media'))) { $value = get_permalink($this->id()); } elseif ('taxonomy' == $this->pod_data['type']) { $value = get_term_link($this->id(), $this->pod_data['name']); } elseif ('user' == $this->pod_data['type']) { $value = get_author_posts_url($this->id()); } elseif ('comment' == $this->pod_data['type']) { $value = get_comment_link($this->id()); } } $field_data = false; $field_type = false; $first_field = explode('.', $params->name); $first_field = $first_field[0]; if (isset($this->fields[$first_field])) { $field_data = $this->fields[$first_field]; $field_type = 'field'; } elseif (isset($this->pod_data['object_fields']) && !empty($this->pod_data['object_fields'])) { if (isset($this->pod_data['object_fields'][$first_field])) { $field_data = $this->pod_data['object_fields'][$first_field]; $field_type = 'object_field'; } else { foreach ($this->pod_data['object_fields'] as $object_field => $object_field_opt) { if (in_array($first_field, $object_field_opt['alias'])) { if ($first_field == $params->name) { $params->name = $object_field; } $first_field = $object_field; $field_data = $object_field_opt; $field_type = 'object_field'; break; } } } } if (empty($value) && isset($this->row[$params->name])) { if (empty($field_data) || in_array($field_data['type'], array('boolean', 'number', 'currency')) || in_array($field_data['type'], $tableless_field_types)) { $params->raw = true; } $value = $this->row[$params->name]; if (!is_array($value) && 'pick' == $field_data['type'] && in_array($field_data['pick_object'], $simple_tableless_objects)) { $value = PodsForm::field_method('pick', 'simple_value', $params->name, $value, $field_data, $this->pod_data, $this->id(), true); } } elseif (empty($value)) { $object_field_found = false; if ('object_field' == $field_type) { $object_field_found = true; if (isset($this->row[$first_field])) { $value = $this->row[$first_field]; } elseif (in_array($field_data['type'], $tableless_field_types)) { $this->fields[$first_field] = $field_data; $object_field_found = false; } else { return null; } } if ('post_type' == $this->pod_data['type'] && !isset($this->fields[$params->name])) { if (!isset($this->fields['post_thumbnail']) && ('post_thumbnail' == $params->name || 0 === strpos($params->name, 'post_thumbnail.'))) { $size = 'thumbnail'; if (0 === strpos($params->name, 'post_thumbnail.')) { $field_names = explode('.', $params->name); if (isset($field_names[1])) { $size = $field_names[1]; } } // Pods will auto-get the thumbnail ID if this isn't an attachment $value = pods_image($this->id(), $size); $object_field_found = true; } elseif (!isset($this->fields['post_thumbnail_url']) && ('post_thumbnail_url' == $params->name || 0 === strpos($params->name, 'post_thumbnail_url.'))) { $size = 'thumbnail'; if (0 === strpos($params->name, 'post_thumbnail_url.')) { $field_names = explode('.', $params->name); if (isset($field_names[1])) { $size = $field_names[1]; } } // Pods will auto-get the thumbnail ID if this isn't an attachment $value = pods_image_url($this->id(), $size); $object_field_found = true; } } elseif ('user' == $this->pod_data['type'] && !isset($this->fields[$params->name])) { if (!isset($this->fields['avatar']) && ('avatar' == $params->name || 0 === strpos($params->name, 'avatar.'))) { $size = null; if (0 === strpos($params->name, 'avatar.')) { $field_names = explode('.', $params->name); if (isset($field_names[1])) { $size = (int) $field_names[1]; } } if (!empty($size)) { $value = get_avatar($this->id(), $size); } else { $value = get_avatar($this->id()); } $object_field_found = true; } } elseif (0 === strpos($params->name, 'image_attachment.')) { $size = 'thumbnail'; $image_id = 0; $field_names = explode('.', $params->name); if (isset($field_names[1])) { $image_id = $field_names[1]; } if (isset($field_names[2])) { $size = $field_names[2]; } if (!empty($image_id)) { $value = pods_image($image_id, $size); if (!empty($value)) { $object_field_found = true; } } } elseif (0 === strpos($params->name, 'image_attachment_url.')) { $size = 'thumbnail'; $image_id = 0; $field_names = explode('.', $params->name); if (isset($field_names[1])) { $image_id = $field_names[1]; } if (isset($field_names[2])) { $size = $field_names[2]; } if (!empty($image_id)) { $value = pods_image_url($image_id, $size); if (!empty($value)) { $object_field_found = true; } } } if (false === $object_field_found) { $params->traverse = array($params->name); if (false !== strpos($params->name, '.')) { $params->traverse = explode('.', $params->name); $params->name = $params->traverse[0]; } if (isset($this->fields[$params->name]) && isset($this->fields[$params->name]['type'])) { $v = $this->do_hook('field_' . $this->fields[$params->name]['type'], null, $this->fields[$params->name], $this->row, $params); if (null !== $v) { return $v; } } $simple = false; $simple_data = array(); if (isset($this->fields[$params->name])) { if ('meta' == $this->pod_data['storage']) { if (!in_array($this->fields[$params->name]['type'], $tableless_field_types)) { $simple = true; } } if (in_array($this->fields[$params->name]['type'], $tableless_field_types)) { $params->raw = true; if ('pick' == $this->fields[$params->name]['type'] && in_array($this->fields[$params->name]['pick_object'], $simple_tableless_objects)) { $simple = true; $params->single = true; } } elseif (in_array($this->fields[$params->name]['type'], array('boolean', 'number', 'currency'))) { $params->raw = true; } } if (!isset($this->fields[$params->name]) || !in_array($this->fields[$params->name]['type'], $tableless_field_types) || $simple) { if (null === $params->single) { if (isset($this->fields[$params->name]) && !in_array($this->fields[$params->name]['type'], $tableless_field_types)) { $params->single = true; } else { $params->single = false; } } $no_conflict = pods_no_conflict_check($this->pod_data['type']); if (!$no_conflict) { pods_no_conflict_on($this->pod_data['type']); } if (in_array($this->pod_data['type'], array('post_type', 'media'))) { $id = $this->id(); // Support for WPML 'duplicated' translation handling if (is_object($sitepress) && $sitepress->is_translated_post_type($this->pod_data['name'])) { $master_post_id = (int) get_post_meta($id, '_icl_lang_duplicate_of', true); if (0 < $master_post_id) { $id = $master_post_id; } } $value = get_post_meta($id, $params->name, $params->single); } elseif (in_array($this->pod_data['type'], array('user', 'comment'))) { $value = get_metadata($this->pod_data['type'], $this->id(), $params->name, $params->single); } elseif ('settings' == $this->pod_data['type']) { $value = get_option($this->pod_data['name'] . '_' . $params->name, null); } // Handle Simple Relationships if ($simple) { if (null === $params->single) { $params->single = false; } $value = PodsForm::field_method('pick', 'simple_value', $params->name, $value, $this->fields[$params->name], $this->pod_data, $this->id(), true); } if (!$no_conflict) { pods_no_conflict_off($this->pod_data['type']); } } else { // Dot-traversal $pod = $this->pod; $ids = array($this->id()); $all_fields = array($this->pod => $this->fields); $lookup = $params->traverse; if (!empty($lookup)) { unset($lookup[0]); } // Get fields matching traversal names if (!empty($lookup)) { $fields = $this->api->load_fields(array('name' => $lookup, 'type' => $tableless_field_types)); if (!empty($fields)) { foreach ($fields as $field) { if (!empty($field)) { if (!isset($all_fields[$field['pod']])) { $all_fields[$field['pod']] = array(); } $all_fields[$field['pod']][$field['name']] = $field; } } } } $last_type = $last_object = $last_pick_val = ''; $last_options = array(); $single_multi = pods_var($this->fields[$params->name]['type'] . '_format_type', $this->fields[$params->name]['options'], 'single'); if ('multi' == $single_multi) { $limit = (int) pods_var($this->fields[$params->name]['type'] . '_limit', $this->fields[$params->name]['options'], 0); } else { $limit = 1; } $last_limit = 0; // Loop through each traversal level foreach ($params->traverse as $key => $field) { $last_loop = false; if (count($params->traverse) <= $key + 1) { $last_loop = true; } $field_exists = isset($all_fields[$pod][$field]); $simple = false; $last_options = array(); if ($field_exists && 'pick' == $all_fields[$pod][$field]['type'] && in_array($all_fields[$pod][$field]['pick_object'], $simple_tableless_objects)) { $simple = true; $last_options = $all_fields[$pod][$field]; } // Tableless handler if ($field_exists && ('pick' != $all_fields[$pod][$field]['type'] || !$simple)) { $type = $all_fields[$pod][$field]['type']; $pick_object = $all_fields[$pod][$field]['pick_object']; $pick_val = $all_fields[$pod][$field]['pick_val']; if ('table' == $pick_object) { $pick_val = pods_var('pick_table', $all_fields[$pod][$field]['options'], $pick_val, null, true); } if ('__current__' == $pick_val) { $pick_val = $pod; } $last_limit = 0; if (in_array($type, $tableless_field_types)) { $single_multi = pods_var("{$type}_format_type", $all_fields[$pod][$field]['options'], 'single'); if ('multi' == $single_multi) { $last_limit = (int) pods_var("{$type}_limit", $all_fields[$pod][$field]['options'], 0); } else { $last_limit = 1; } } $last_type = $type; $last_object = $pick_object; $last_pick_val = $pick_val; $last_options = $all_fields[$pod][$field]; // Temporary hack until there's some better handling here $last_limit = $last_limit * count($ids); // Get related IDs $ids = $this->api->lookup_related_items($all_fields[$pod][$field]['id'], $all_fields[$pod][$field]['pod_id'], $ids, $all_fields[$pod][$field]); // No items found if (empty($ids)) { return false; } elseif (0 < $last_limit) { $ids = array_slice($ids, 0, $last_limit); } // Get $pod if related to a Pod if (!empty($pick_object) && !empty($pick_val)) { if ('pod' == $pick_object) { $pod = $pick_val; } else { $check = $this->api->get_table_info($pick_object, $pick_val); if (!empty($check) && !empty($check['pod'])) { $pod = $check['pod']['name']; } } } } else { // Invalid field if (0 == $key) { return false; } $last_loop = true; } if ($last_loop) { $object_type = $last_object; $object = $last_pick_val; if (in_array($last_type, PodsForm::file_field_types())) { $object_type = 'media'; $object = 'attachment'; } $data = array(); $table = $this->api->get_table_info($object_type, $object, null, null, $last_options); $join = $where = array(); if (!empty($table['join'])) { $join = (array) $table['join']; } if (!empty($table['where']) || !empty($ids)) { foreach ($ids as $id) { $where[$id] = '`t`.`' . $table['field_id'] . '` = ' . (int) $id; } if (!empty($where)) { $where = array(implode(' OR ', $where)); } if (!empty($table['where'])) { $where = array_merge($where, array_values((array) $table['where'])); } } /** * @var $related_obj Pods */ $related_obj = false; if ('pod' == $object_type) { $related_obj = pods($object, null, false); } elseif (isset($table['pod']) && !empty($table['pod'])) { $related_obj = pods($table['pod']['name'], null, false); } if (!empty($table['table']) || !empty($related_obj)) { $sql = array('select' => '*, `t`.`' . $table['field_id'] . '` AS `pod_item_id`', 'table' => $table['table'], 'join' => $join, 'where' => $where, 'orderby' => $params->orderby, 'pagination' => false, 'search' => false, 'limit' => -1); // Output types if (in_array($params->output, array('ids', 'objects'))) { $sql['select'] = '`t`.`' . $table['field_id'] . '` AS `pod_item_id`'; } elseif ('names' == $params->output && !empty($table['field_index'])) { $sql['select'] = '`t`.`' . $table['field_index'] . '` AS `pod_item_index`, `t`.`' . $table['field_id'] . '` AS `pod_item_id`'; } if (is_array($params->params) && !empty($params->params)) { $where = $sql['where']; $sql = array_merge($sql, $params->params); if (isset($params->params['where'])) { $sql['where'] = array_merge((array) $where, (array) $params->params['where']); } } if (empty($related_obj)) { if (!is_object($this->alt_data)) { $this->alt_data = pods_data(null, 0, true, true); } $item_data = $this->alt_data->select($sql); } else { $item_data = $related_obj->find($sql)->data(); } $items = array(); if (!empty($item_data)) { foreach ($item_data as $item) { if (is_array($item)) { $item = (object) $item; } if (empty($item->pod_item_id)) { continue; } // Bypass pass field if (isset($item->user_pass)) { unset($item->user_pass); } // Get Item ID $item_id = $item->pod_item_id; // Cleanup unset($item->pod_item_id); // Output types if ('ids' == $params->output) { $item = (int) $item_id; } elseif ('objects' == $params->output) { if (in_array($object_type, array('post_type', 'media'))) { $item = get_post($item_id); } elseif ('taxonomy' == $object_type) { $item = get_term($item_id, $object); } elseif ('user' == $object_type) { $item = get_userdata($item_id); } elseif ('comment' == $object_type) { $item = get_comment($item_id); } else { $item = (object) $item; } } elseif ('names' == $params->output && !empty($table['field_index'])) { $item = $item->pod_item_index; } else { // arrays $item = get_object_vars((object) $item); } // Pass item data into $data $items[$item_id] = $item; } // Cleanup unset($item_data); // Return all of the data in the order expected if (empty($params->orderby)) { foreach ($ids as $id) { if (isset($items[$id])) { $data[$id] = $items[$id]; } } } } } if (in_array($last_type, $tableless_field_types) || in_array($last_type, array('boolean', 'number', 'currency'))) { $params->raw = true; } if (empty($data)) { $value = false; } else { $object_type = $table['type']; if (in_array($table['type'], array('post_type', 'attachment', 'media'))) { $object_type = 'post'; } $no_conflict = true; if (in_array($object_type, array('post', 'user', 'comment', 'settings'))) { $no_conflict = pods_no_conflict_check($object_type); if (!$no_conflict) { pods_no_conflict_on($object_type); } } // Return entire array if (false === $params->in_form && false !== $field_exists && in_array($last_type, $tableless_field_types)) { $value = $data; } else { $value = array(); if ($params->in_form) { $field = $table['field_id']; } foreach ($data as $item_id => $item) { if ((false !== strpos($field, '_src') || 'guid' == $field) && (in_array($table['type'], array('attachment', 'media')) || in_array($last_type, PodsForm::file_field_types())) || (in_array($field, array('_link', 'detail_url')) || in_array($field, array('permalink', 'the_permalink')) && in_array($last_type, PodsForm::file_field_types()))) { $size = 'full'; if (false !== strpos($field, '_src.') && 5 < strlen($field)) { $size = substr($field, 5); } $value[] = pods_image_url($item_id, $size); $params->raw_display = true; } elseif (false !== strpos($field, '_img') && (in_array($table['type'], array('attachment', 'media')) || in_array($last_type, PodsForm::file_field_types()))) { $size = 'full'; if (false !== strpos($field, '_img.') && 5 < strlen($field)) { $size = substr($field, 5); } $value[] = pods_image($item_id, $size); $params->raw_display = true; } elseif (in_array($field, array('_link', 'detail_url')) || in_array($field, array('permalink', 'the_permalink')) && 'post' == $object_type) { if ('pod' == $object_type) { if (is_object($related_obj)) { $related_obj->fetch($item_id); $value[] = $related_obj->field('detail_url'); } else { $value[] = ''; } } elseif ('post' == $object_type) { $value[] = get_permalink($item_id); } elseif ('taxonomy' == $object_type) { $value[] = get_term_link($item_id, $object); } elseif ('user' == $object_type) { $value[] = get_author_posts_url($item_id); } elseif ('comment' == $object_type) { $value[] = get_comment_link($item_id); } else { $value[] = ''; } $params->raw_display = true; } elseif (is_array($item) && isset($item[$field])) { if ($table['field_id'] == $field) { $value[] = (int) $item[$field]; } else { $value[] = $item[$field]; } } elseif (is_object($item) && isset($item->{$field})) { if ($table['field_id'] == $field) { $value[] = (int) $item->{$field}; } else { $value[] = $item->{$field}; } } elseif ('post' == $object_type) { // Support for WPML 'duplicated' translation handling if (is_object($sitepress) && $sitepress->is_translated_post_type($object)) { $master_post_id = (int) get_post_meta($item_id, '_icl_lang_duplicate_of', true); if (0 < $master_post_id) { $item_id = $master_post_id; } } $value[] = get_post_meta($item_id, $field, true); } elseif (in_array($object_type, array('post', 'user', 'comment'))) { $value[] = get_metadata($object_type, $item_id, $field, true); } elseif ('settings' == $object_type) { $value[] = get_option($object . '_' . $field); } } } if (in_array($object_type, array('post', 'user', 'comment', 'settings')) && !$no_conflict) { pods_no_conflict_off($object_type); } // Handle Simple Relationships if ($simple) { if (null === $params->single) { $params->single = false; } $value = PodsForm::field_method('pick', 'simple_value', $field, $value, $last_options, $all_fields[$pod], 0, true); } elseif (false === $params->in_form && !empty($value)) { $value = array_values($value); } // Return a single column value if (false === $params->in_form && 1 == $limit && !empty($value) && is_array($value) && 1 == count($value)) { $value = current($value); } } break; } } } } } if (!empty($params->traverse) && 1 < count($params->traverse)) { $field_names = implode('.', $params->traverse); $this->row[$field_names] = $value; } else { $this->row[$params->name] = $value; } if ($params->single && is_array($value) && 1 == count($value)) { $value = current($value); } // @todo Expand this into traversed fields too if (!empty($field_data) && ($params->display || !$params->raw) && !$params->in_form && !$params->raw_display) { if ($params->display || ($params->get_meta || $params->deprecated) && !in_array($field_data['type'], $tableless_field_types)) { $field_data['options'] = pods_var_raw('options', $field_data, array(), null, true); $post_temp = false; if ('post_type' == pods_var('type', $this->pod_data) && 0 < $this->id() && (!isset($GLOBALS['post']) || empty($GLOBALS['post']))) { global $post_ID, $post; $post_temp = true; $old_post = $GLOBALS['post']; $old_ID = $GLOBALS['post_ID']; $post = get_post($this->id()); $post_ID = $this->id(); } $filter = pods_var_raw('display_filter', $field_data['options']); if (0 < strlen($filter)) { $args = array($filter, $value); $filter_args = pods_var_raw('display_filter_args', $field_data['options']); if (!empty($filter_args)) { $args = array_merge($args, compact($filter_args)); } $value = call_user_func_array('apply_filters', $args); } elseif (1 == pods_var('display_process', $field_data['options'], 1)) { $value = PodsForm::display($field_data['type'], $value, $params->name, array_merge($field_data, $field_data['options']), $this->pod_data, $this->id()); } if ($post_temp) { $post = $old_post; $post_ID = $old_ID; } } else { $value = PodsForm::value($field_data['type'], $value, $params->name, array_merge($field_data, $field_data['options']), $this->pod_data, $this->id()); } } $value = $this->do_hook('field', $value, $this->row, $params); return $value; }