private static function getAJAXSubPosts($field_assigned_to, $parent_id) { $array_ids = array_map(function ($id) { return trim((int) $id); }, $_POST['array_ids']); // remove any sub-posts without parents //self::removeAbandonedPosts(); $records = \Taco\Post\Factory::createMultiple($array_ids); $all_records = self::getChildPosts($parent_id); $diff = array_diff(Collection::pluck($all_records, 'ID'), $array_ids); if (Arr::iterable($diff)) { $records = array_merge($records, \Taco\Post\Factory::createMultiple($diff)); } // filter out the fields we don't need $filtered = array_map(function ($subpost) use($field_assigned_to, $parent_id) { $post_title = $subpost->post_title; $fields_variation = $subpost->get('fields_variation'); $fields_attribs = self::getFieldDefinitionKeyAttribs($field_assigned_to, $parent_id, $fields_variation); if (!Arr::iterable($fields_attribs)) { return []; } $subfields = self::getFieldDefinitionKeys($field_assigned_to, $parent_id, $fields_variation); if (!Arr::iterable($subfields)) { $subfields = array(); } if (isset($subpost->post_title) && preg_match('/[&\']{1,}/', $subpost->post_title)) { $post_title = stripslashes($subpost->post_title); } $array_fields_values = []; foreach ($subfields as $key) { $array_fields_values[$key] = array('value' => $subpost->get($key), 'attribs' => $fields_attribs[$key]); } return array_merge(array('fields' => $array_fields_values), array('post_id' => $subpost->ID, 'fields_variation' => $subpost->get('fields_variation'))); }, $records); header('Content-Type: application/json'); echo json_encode(array('success' => true, 'posts' => array_filter($filtered))); exit; }
<?php echo $resources_search->renderGroup('taxonomy', 1); ?> </div> </div> <?php echo $resources_search->renderSearchFormFooter(); ?> <?php $results = $resources_search->getSearchresults(); if (\AppLibrary\Arr::iterable($results)) { ?> <?php $result_posts = \Taco\Post\Factory::createMultiple($results); ?> <?php foreach ($result_posts as $r) { ?> <div class="row"> <div class="small-12 columns"> <hr> <?php echo $r->getTheTitle(); ?> <?php echo $r->getTheContent(); ?> <?php
/** * Get results by page * @param int $page * @param array $args * @param string $sort * @param bool $load_terms */ public static function getPage($page = 1, $args = array(), $load_terms = true) { $instance = Post\Factory::create(get_called_class()); $criteria = array('post_type' => $instance->getPostType(), 'orderby' => 'date', 'order' => 'DESC', 'posts_per_page' => $instance->getPostsPerPage(), 'offset' => ($page - 1) * $instance->getPostsPerPage()); $criteria = array_merge($criteria, $args); return Post\Factory::createMultiple(get_posts($criteria), $load_terms); }
/** * Get Taco Posts or Terms in the order specficied using a string of comma seperated ids * @param string $string_order comma seperated list of ids * @param bool $reverse should the collection be reversed * @param bool $is_term should the method return terms instead of posts * @param string $taxonomy if this method is returning terms, what taxonomy do they belong to * @param bool $load_terms should terms be loaded with posts * @return array */ public static function getPostsFromOrder($string_order = '', $reverse = false, $is_term = false, $taxonomy = null, $load_terms = true) { if (!strlen($string_order)) { return array(); } if (!preg_match('/\\d+/', $string_order)) { return array(); } $ids_array = explode(',', trim(strip_tags($string_order))); if (!$is_term) { $ids_array = self::getItemsIfExists($ids_array, $is_term); $items = \Taco\Post\Factory::createMultiple($ids_array, $load_terms); } else { $ids_array = self::getItemsIfExists($ids_array, true); $items = \Taco\Term\Factory::createMultiple($ids_array, $taxonomy); } $items = $reverse ? array_reverse($items) : $items; return Arr::iterable($items) ? $items : array(); }