/** * Apply the filter. * * @param mixed input: a single post ID or an array of them * @param string formatting string OR clickable title * @return mixed */ public function filter($input, $options = null) { $output = ''; // Gotta set the default here due to how print_custom_field calls get_custom_field if (empty($options)) { $options = '<a href="[+permalink+]" title="[+post_title+]">[+post_title+]</a>'; } elseif (strpos($options, '[+') === false) { $options = '<a href="[+permalink+]" title="[+post_title+]">' . $options . '</a>'; } $input = $this->to_array($input); if (empty($input)) { return ''; } $output = ''; if ($this->is_array_input) { foreach ($input as &$item) { if ($item) { //$post = get_post($item); if (!is_numeric($item)) { $item = sprintf(__('Invalid input. %s operates on post IDs only.', CCTM_TXTDOMAIN), 'to_link'); continue; } $post = get_post_complete($item); if (!is_array($post)) { $item = __('Referenced post not found.', CCTM_TXTDOMAIN); continue; } $link_text = $post['post_title']; $item = CCTM::parse($options, $post); } } return implode(', ', $input); } else { if (!is_numeric($input[0])) { return sprintf(__('Invalid input. %s operates on post IDs only.', CCTM_TXTDOMAIN), 'to_link'); } $post = get_post_complete($input[0]); if (!is_array($post)) { return _e('Referenced post not found.', CCTM_TXTDOMAIN); } return CCTM::parse($options, $post); } }
/** * Convert a post id to an array represent the post and all its data. * * @param mixed integer post_id or an array of post_id's * @param string optional field name to return OR a formatting string with [+placeholders+] * @return mixed */ public function filter($input, $options = null) { $input = $this->to_array($input); if ($options && is_scalar($options)) { $output = ''; } else { $output = array(); } if (empty($input)) { return false; } if ($this->is_array_input) { foreach ($input as $k => $item) { $item = (int) $item; $post = get_post_complete($item); if ($options && is_scalar($options)) { if (isset($post[$options])) { $output .= $post[$options]; } else { $output .= CCTM::parse($options, $post); } } else { $output[] = $post; } } return $output; } else { $input = (int) $input[0]; if ($options && is_scalar($options)) { $post = get_post_complete($input); if (isset($post[$options])) { return $post[$options]; } return CCTM::parse($options, $post); } else { return get_post_complete($input); } } }
function test_get_post_complete() { $post = get_post_complete(123); $this->assertTrue($post['post_name'] == 'img_0448'); }
function get_relation($fieldname) { return get_post_complete(get_custom_field($fieldname)); }