function get_subpages($page_name) { $my_wp_query = new WP_Query(); $all_wp_pages = $my_wp_query->query(array('post_type' => 'page')); $pg = get_page_by_title($page_name); return get_page_children($pg->ID, $all_wp_pages); }
function widget($args, $instance) { extract($args); $title = apply_filters('widget_title', $instance['title']); $show_modified_date = $instance['show_modified_date']; $show_published_date = $instance['show_published_date']; $show_author = $instance['show_author']; global $post; $tzone = get_option('timezone_string'); date_default_timezone_set($tzone); $sdate = human_time_diff_plus(get_the_modified_time('U')); $pdate = human_time_diff_plus(date("U", strtotime($post->post_date))); $userid = $post->post_author; $acf_key = "widget_" . $this->id_base . "-" . $this->number . "_about_this_page_children"; $aboutChildren = get_option($acf_key); if (is_single()) { $single = 'true'; } if (is_singular(array('forum', 'topic', 'reply'))) { $single_forum = 'true'; } $page = is_page(); $showabout = false; if ($single) { $showabout = true; } if ($single_forum) { $showabout = false; } if ($page) { $my_wp_query = new WP_Query(); $all_wp_pages = $my_wp_query->query(array('post_type' => 'page', 'posts_per_page' => -1)); if ($aboutChildren) { foreach ((array) $aboutChildren as $a) { // Filter through all pages and find Portfolio's children $children = get_page_children($a, $all_wp_pages); if ($children) { foreach ($children as $c) { $child[] = $c->ID; if ($post->ID == $c->ID) { $showabout = true; } } } } } } $path = plugin_dir_url(__FILE__); wp_enqueue_script('ht_about_this_page_ajax', $path . 'ht_about_this_page_ajax.js'); $protocol = isset($_SERVER["HTTPS"]) ? 'https://' : 'http://'; $params = array('ajaxurl' => admin_url('admin-ajax.php', $protocol), 'title' => $title, 'before_widget' => stripcslashes($before_widget), 'after_widget' => stripcslashes($after_widget), 'before_title' => stripcslashes($before_title), 'after_title' => stripcslashes($after_title), 'show_modified_date' => $show_modified_date, 'show_published_date' => $show_published_date, 'show_author' => $show_author, 'single' => $single, 'single_forum' => $single_forum, 'page' => $page, 'sdate' => $sdate, 'pdate' => $pdate, 'userid' => $userid, 'showabout' => $showabout); wp_localize_script('ht_about_this_page_ajax', 'ht_about_this_page_ajax', $params); echo "<div id='ht_about_this_page_ajax' class='ht_about_this_page_ajax'></div>"; }
/** * Get page hierarchy */ function wanderoper_permalink() { // Set up the objects needed $my_wp_query = new WP_Query(); $all_wp_pages = $my_wp_query->query(array('post_type' => 'page')); // Get the page as an Object $Repertoire = get_page_by_title('Repertoire'); // Filter through all pages and find Portfolio's children $Repertoire_children = get_page_children($Repertoire->ID, $all_wp_pages); // echo what we get back from WP to the browser echo '<pre>' . print_r($Repertoire_children, true) . '</pre>'; }
public function getPageChildren($id = 0) { $all_pages = get_posts(array('post_type' => 'page')); $page_children = get_page_children($id, $all_pages); if (is_array($page_children)) { $page_children_obj = array(); foreach ($page_children as $child) { $page_children_obj[] = PageDataHelper::createPageObject(false, $child); } return $page_children_obj; } else { return null; } }
private function setup($exclude_relations = [], $qrfields = []) { $postObject = get_post($this->id); $post_type = strtolower(get_called_class()); $_class = get_called_class(); $image_sizes = array_merge(['thumbnail', 'medium', 'large', 'full'], $this->getSizes()); $fields = $this->getFields(); $taxonomies = $this->getTaxonomies(); $modelDefaultFields = ['title', 'thumbnail', 'editor']; $multipleFields = ['checkbox_list', 'plupload_image', 'checkbox_tree']; // Post default properties foreach ($postObject as $key => $value) { $chave = str_replace('post_', '', $key); if ($this->shouldMount("post", $qrfields) || $this->shouldMount($chave, $qrfields)) { $this->{$chave} = $value; } } // Permalink if ($this->shouldMount('permalink', $qrfields)) { $this->permalink = get_permalink($this->ID); } // Default post taxonomies if ($post_type == "post" && empty($taxonomies)) { $taxonomies = array("post_tag", "category"); } // Author $author = new \stdClass(); if ($this->shouldMount('author', $qrfields)) { foreach (array('ID', 'display_name', 'nickname', 'first_name', 'last_name', 'description', 'email') as $field) { $author->{$field} = get_the_author_meta($field, $this->author); } } if ($this->shouldMount('author', $qrfields)) { $this->author = $author; } if ($post_type == "post" || $this->shouldMount('content', $qrfields)) { $this->content = apply_filters('the_content', $this->content); } // Terms if (!empty($taxonomies) && $this->shouldMount('taxonomies', $qrfields)) { foreach ($taxonomies as $taxonomy) { $terms = array(); $obj = get_the_terms($this->ID, $taxonomy); if (is_array($obj)) { foreach ($obj as $term) { $term->link = get_term_link($term->term_id, $taxonomy); array_push($terms, $term); } } $this->{$taxonomy} = $terms; } } // Custom fields foreach ($fields as $key => $value) { $is_multiple = !empty($value['multiple']) && $value['multiple']; if (!in_array($key, $modelDefaultFields) && $this->shouldMount($key, $qrfields)) { if ($value['type'] !== 'image' && $value['type'] !== 'file') { if ($is_multiple || in_array($value['type'], $multipleFields)) { $this->{$key} = get_post_meta($postObject->ID, $key); } else { $this->{$key} = get_post_meta($postObject->ID, $key, true); } } else { switch ($value['type']) { case 'image': $this->{$key} = $this->getImage($postObject, $key, $value); break; case 'file': $this->{$key} = $this->getFile($postObject, $key, $value); break; } } } } // Relations $has_many = Store::get('relation_has_many'); if ($this->shouldMount('relations', $qrfields)) { foreach ($has_many as $many) { if ($many['target'] == $post_type && !in_array($many['model'], $exclude_relations)) { $manyqr = new \WP_Query(['post_type' => $many['model'], 'meta_key' => $many['target'], 'meta_value' => $this->ID]); if ($manyqr->have_posts()) { $ids = []; foreach ($manyqr->posts as $_post) { $klass = $this->getClass($many['model']); array_push($ids, new $klass($_post->ID, [$many['target']])); } $this->{$many['model']} = $ids; } else { $this->{$many['model']} = []; } } else { if ($many['model'] == $post_type) { if (is_array($this->{$many['target']})) { $ids = []; foreach ($this->{$many['target']} as $item) { $klass = $this->getClass($many['target']); array_push($ids, new $klass($item, [$many['model']])); } $this->{$many['target']} = $ids; } else { $klass = $this->getClass($many['target']); $this->{$many['target']} = new $klass($this->{$many['target']}, [$many['model']]); } } } } } $belongs_to = Store::get('relation_belongs_to'); if ($this->shouldMount('relations', $qrfields)) { foreach ($belongs_to as $bel) { if ($bel['target'] == $post_type && !in_array($bel['model'], $exclude_relations)) { $belqr = new \WP_Query(['post_type' => $bel['model'], 'meta_key' => $bel['target'], 'meta_value' => $this->ID]); if ($belqr->have_posts()) { $klass = $this->getClass($bel['model']); $this->{$bel['model']} = new $klass($belqr->posts[0], [$bel['target']]); } else { $this->{$bel['model']} = null; } } else { if ($bel['model'] == $post_type) { $klass = $this->getClass($bel['target']); $this->{$bel['target']} = new $klass($this->{$bel['target']}, [$bel['model']]); } } } } // Include subpages if ($post_type == 'page' && $this->shouldMount('children', $qrfields)) { $my_wp_query = new \WP_Query(); $all_wp_pages = $my_wp_query->query(array('post_type' => 'page')); // Filter through all pages and find Portfolio's children $children = get_page_children($this->ID, $all_wp_pages); $this->children = array(); foreach ($children as $child) { array_push($this->children, \Page::findById($child->ID)); } } // Set the thumbnail if ($this->shouldMount('thumbnail', $qrfields)) { $image = get_post_thumbnail_id($postObject->ID); $img = new \stdClass(); foreach ($image_sizes as $s) { $wp_image = wp_get_attachment_image_src($image, $s); $img->{$s} = $wp_image[0]; } $this->thumbnail = $img; } }
<?php /** * Template part for displaying page content in page.php. * * @link https://codex.wordpress.org/Template_Hierarchy * * @package judd-foundation */ $query = new WP_Query(); $pages = $query->query(array('post_type' => 'page')); get_page_children($page_id, $pages); ?> <article id="page-<?php the_ID(); ?> " class="twoColumn"> <!--<h2><?php the_title(); ?> </h2>--> <!--<?php $args = array('post_parent' => get_the_ID(), 'post_status' => 'publish'); $child_page = get_children($args); if ($child_page) { echo '<div class="sub-nav">'; foreach ($child_page as $child) { $childID = $child->ID;
/** * fr_get_sitemap * Outputs a hierarchical sitemap. * * @since 1.0.0 * @version 1.0.0 **/ function fr_get_sitemap() { $args = array('sort_order' => 'ASC', 'sort_column' => 'menu_order', 'hierarchical' => 1, 'post_type' => 'page', 'post_status' => 'publish'); $pages = get_pages($args); ?> <ul class="post-tags"> <?php foreach ($pages as $page) { ?> <?php if (!$page->post_parent) { ?> <?php $children = get_page_children($page->ID, $pages); ?> <li> <a href="<?php echo get_permalink($page->ID); ?> " title="View the <?php echo $page->post_title; ?> page"><?php echo $page->post_title; ?> </a> <?php if (!empty($children)) { ?> <ul> <?php foreach ($children as $child) { ?> <li> <a href="<?php echo get_permalink($child->ID); ?> " title="View the <?php echo $child->post_title; ?> page"><?php echo $child->post_title; ?> </a> </li> <?php } ?> </ul> <?php } ?> </li> <?php } ?> <?php } ?> </ul> <?php }
function acf_get_grouped_posts($args) { // vars $r = array(); // defaults $args = acf_parse_args($args, array('posts_per_page' => -1, 'paged' => 0, 'post_type' => 'post', 'orderby' => 'menu_order title', 'order' => 'ASC', 'post_status' => 'any', 'suppress_filters' => false, 'update_post_meta_cache' => false)); // find array of post_type $post_types = acf_force_type_array($args['post_type']); $post_types_labels = acf_get_pretty_post_types($post_types); // attachment doesn't work if it is the only item in an array if (count($post_types) == 1) { $args['post_type'] = current($post_types); } // add filter to orderby post type add_filter('posts_orderby', '_acf_orderby_post_type', 10, 2); // get posts $posts = get_posts($args); // loop foreach ($post_types as $post_type) { // vars $this_posts = array(); $this_group = array(); // populate $this_posts foreach (array_keys($posts) as $key) { if ($posts[$key]->post_type == $post_type) { $this_posts[] = acf_extract_var($posts, $key); } } // bail early if no posts for this post type if (empty($this_posts)) { continue; } // sort into hierachial order! // this will fail if a search has taken place because parents wont exist if (is_post_type_hierarchical($post_type) && empty($args['s'])) { // vars $match_id = $this_posts[0]->ID; $offset = 0; $length = count($this_posts); $parent = acf_maybe_get($args, 'post_parent', 0); // reset $this_posts $this_posts = array(); // get all posts $all_args = array_merge($args, array('posts_per_page' => -1, 'paged' => 0, 'post_type' => $post_type)); $all_posts = get_posts($all_args); // loop over posts and find $i foreach ($all_posts as $offset => $p) { if ($p->ID == $match_id) { break; } } // order posts $all_posts = get_page_children($parent, $all_posts); for ($i = $offset; $i < $offset + $length; $i++) { $this_posts[] = acf_extract_var($all_posts, $i); } } // populate $this_posts foreach (array_keys($this_posts) as $key) { // extract post $post = acf_extract_var($this_posts, $key); // add to group $this_group[$post->ID] = $post; } // group by post type $post_type_name = $post_types_labels[$post_type]; $r[$post_type_name] = $this_group; } // return return $r; }
/** * Retrieve a list of pages. * * @global wpdb $wpdb WordPress database abstraction object. * * @since 1.5.0 * * @param array|string $args { * Optional. Array or string of arguments to retrieve pages. * * @type int $child_of Page ID to return child and grandchild pages of. Note: The value * of `$hierarchical` has no bearing on whether `$child_of` returns * hierarchical results. Default 0, or no restriction. * @type string $sort_order How to sort retrieved pages. Accepts 'ASC', 'DESC'. Default 'ASC'. * @type string $sort_column What columns to sort pages by, comma-separated. Accepts 'post_author', * 'post_date', 'post_title', 'post_name', 'post_modified', 'menu_order', * 'post_modified_gmt', 'post_parent', 'ID', 'rand', 'comment_count'. * 'post_' can be omitted for any values that start with it. * Default 'post_title'. * @type bool $hierarchical Whether to return pages hierarchically. If false in conjunction with * `$child_of` also being false, both arguments will be disregarded. * Default true. * @type array $exclude Array of page IDs to exclude. Default empty array. * @type array $include Array of page IDs to include. Cannot be used with `$child_of`, * `$parent`, `$exclude`, `$meta_key`, `$meta_value`, or `$hierarchical`. * Default empty array. * @type string $meta_key Only include pages with this meta key. Default empty. * @type string $meta_value Only include pages with this meta value. Requires `$meta_key`. * Default empty. * @type string $authors A comma-separated list of author IDs. Default empty. * @type int $parent Page ID to return direct children of. Default -1, or no restriction. * @type string|array $exclude_tree Comma-separated string or array of page IDs to exclude. * Default empty array. * @type int $number The number of pages to return. Default 0, or all pages. * @type int $offset The number of pages to skip before returning. Requires `$number`. * Default 0. * @type string $post_type The post type to query. Default 'page'. * @type string $post_status A comma-separated list of post status types to include. * Default 'publish'. * } * @return array|false List of pages matching defaults or `$args`. */ function get_pages($args = array()) { global $wpdb; $defaults = array('child_of' => 0, 'sort_order' => 'ASC', 'sort_column' => 'post_title', 'hierarchical' => 1, 'exclude' => array(), 'include' => array(), 'meta_key' => '', 'meta_value' => '', 'authors' => '', 'parent' => -1, 'exclude_tree' => array(), 'number' => '', 'offset' => 0, 'post_type' => 'page', 'post_status' => 'publish'); $r = wp_parse_args($args, $defaults); $number = (int) $r['number']; $offset = (int) $r['offset']; $child_of = (int) $r['child_of']; $hierarchical = $r['hierarchical']; $exclude = $r['exclude']; $meta_key = $r['meta_key']; $meta_value = $r['meta_value']; $parent = $r['parent']; $post_status = $r['post_status']; // Make sure the post type is hierarchical. $hierarchical_post_types = get_post_types(array('hierarchical' => true)); if (!in_array($r['post_type'], $hierarchical_post_types)) { return false; } if ($parent > 0 && !$child_of) { $hierarchical = false; } // Make sure we have a valid post status. if (!is_array($post_status)) { $post_status = explode(',', $post_status); } if (array_diff($post_status, get_post_stati())) { return false; } // $args can be whatever, only use the args defined in defaults to compute the key. $key = md5(serialize(wp_array_slice_assoc($r, array_keys($defaults)))); $last_changed = wp_cache_get('last_changed', 'posts'); if (!$last_changed) { $last_changed = microtime(); wp_cache_set('last_changed', $last_changed, 'posts'); } $cache_key = "get_pages:{$key}:{$last_changed}"; if ($cache = wp_cache_get($cache_key, 'posts')) { // Convert to WP_Post instances. $pages = array_map('get_post', $cache); /** This filter is documented in wp-includes/post.php */ $pages = apply_filters('get_pages', $pages, $r); return $pages; } $inclusions = ''; if (!empty($r['include'])) { $child_of = 0; //ignore child_of, parent, exclude, meta_key, and meta_value params if using include $parent = -1; $exclude = ''; $meta_key = ''; $meta_value = ''; $hierarchical = false; $incpages = wp_parse_id_list($r['include']); if (!empty($incpages)) { $inclusions = ' AND ID IN (' . implode(',', $incpages) . ')'; } } $exclusions = ''; if (!empty($exclude)) { $expages = wp_parse_id_list($exclude); if (!empty($expages)) { $exclusions = ' AND ID NOT IN (' . implode(',', $expages) . ')'; } } $author_query = ''; if (!empty($r['authors'])) { $post_authors = preg_split('/[\\s,]+/', $r['authors']); if (!empty($post_authors)) { foreach ($post_authors as $post_author) { //Do we have an author id or an author login? if (0 == intval($post_author)) { $post_author = get_user_by('login', $post_author); if (empty($post_author)) { continue; } if (empty($post_author->ID)) { continue; } $post_author = $post_author->ID; } if ('' == $author_query) { $author_query = $wpdb->prepare(' post_author = %d ', $post_author); } else { $author_query .= $wpdb->prepare(' OR post_author = %d ', $post_author); } } if ('' != $author_query) { $author_query = " AND ({$author_query})"; } } } $join = ''; $where = "{$exclusions} {$inclusions} "; if ('' !== $meta_key || '' !== $meta_value) { $join = " LEFT JOIN {$wpdb->postmeta} ON ( {$wpdb->posts}.ID = {$wpdb->postmeta}.post_id )"; // meta_key and meta_value might be slashed $meta_key = wp_unslash($meta_key); $meta_value = wp_unslash($meta_value); if ('' !== $meta_key) { $where .= $wpdb->prepare(" AND {$wpdb->postmeta}.meta_key = %s", $meta_key); } if ('' !== $meta_value) { $where .= $wpdb->prepare(" AND {$wpdb->postmeta}.meta_value = %s", $meta_value); } } if (is_array($parent)) { $post_parent__in = implode(',', array_map('absint', (array) $parent)); if (!empty($post_parent__in)) { $where .= " AND post_parent IN ({$post_parent__in})"; } } elseif ($parent >= 0) { $where .= $wpdb->prepare(' AND post_parent = %d ', $parent); } if (1 == count($post_status)) { $where_post_type = $wpdb->prepare("post_type = %s AND post_status = %s", $r['post_type'], reset($post_status)); } else { $post_status = implode("', '", $post_status); $where_post_type = $wpdb->prepare("post_type = %s AND post_status IN ('{$post_status}')", $r['post_type']); } $orderby_array = array(); $allowed_keys = array('author', 'post_author', 'date', 'post_date', 'title', 'post_title', 'name', 'post_name', 'modified', 'post_modified', 'modified_gmt', 'post_modified_gmt', 'menu_order', 'parent', 'post_parent', 'ID', 'rand', 'comment_count'); foreach (explode(',', $r['sort_column']) as $orderby) { $orderby = trim($orderby); if (!in_array($orderby, $allowed_keys)) { continue; } switch ($orderby) { case 'menu_order': break; case 'ID': $orderby = "{$wpdb->posts}.ID"; break; case 'rand': $orderby = 'RAND()'; break; case 'comment_count': $orderby = "{$wpdb->posts}.comment_count"; break; default: if (0 === strpos($orderby, 'post_')) { $orderby = "{$wpdb->posts}." . $orderby; } else { $orderby = "{$wpdb->posts}.post_" . $orderby; } } $orderby_array[] = $orderby; } $sort_column = !empty($orderby_array) ? implode(',', $orderby_array) : "{$wpdb->posts}.post_title"; $sort_order = strtoupper($r['sort_order']); if ('' !== $sort_order && !in_array($sort_order, array('ASC', 'DESC'))) { $sort_order = 'ASC'; } $query = "SELECT * FROM {$wpdb->posts} {$join} WHERE ({$where_post_type}) {$where} "; $query .= $author_query; $query .= " ORDER BY " . $sort_column . " " . $sort_order; if (!empty($number)) { $query .= ' LIMIT ' . $offset . ',' . $number; } $pages = $wpdb->get_results($query); if (empty($pages)) { /** This filter is documented in wp-includes/post.php */ $pages = apply_filters('get_pages', array(), $r); return $pages; } // Sanitize before caching so it'll only get done once. $num_pages = count($pages); for ($i = 0; $i < $num_pages; $i++) { $pages[$i] = sanitize_post($pages[$i], 'raw'); } // Update cache. update_post_cache($pages); if ($child_of || $hierarchical) { $pages = get_page_children($child_of, $pages); } if (!empty($r['exclude_tree'])) { $exclude = wp_parse_id_list($r['exclude_tree']); foreach ($exclude as $id) { $children = get_page_children($id, $pages); foreach ($children as $child) { $exclude[] = $child->ID; } } $num_pages = count($pages); for ($i = 0; $i < $num_pages; $i++) { if (in_array($pages[$i]->ID, $exclude)) { unset($pages[$i]); } } } $page_structure = array(); foreach ($pages as $page) { $page_structure[] = $page->ID; } wp_cache_set($cache_key, $page_structure, 'posts'); // Convert to WP_Post instances $pages = array_map('get_post', $pages); /** * Filter the retrieved list of pages. * * @since 2.1.0 * * @param array $pages List of pages to retrieve. * @param array $r Array of get_pages() arguments. */ return apply_filters('get_pages', $pages, $r); }
/** * ajax_render_rules * * @description creates the HTML for the field group rules metabox. Called from both Ajax and PHP * @since 2.0 * I took this functions from the awesome Advanced custom fields plugin http://www.advancedcustomfields.com/ */ public static function ajax_render_rules($options = array()) { // defaults $defaults = array('group_id' => 0, 'rule_id' => 0, 'value' => null, 'param' => null); $is_ajax = false; if (isset($_POST['nonce']) && wp_verify_nonce($_POST['nonce'], 'spu_nonce')) { $is_ajax = true; } // Is AJAX call? if ($is_ajax) { $options = array_merge($defaults, $_POST); $options['name'] = 'spu_rules[' . $options['group_id'] . '][' . $options['rule_id'] . '][value]'; } else { $options = array_merge($defaults, $options); } // vars $choices = array(); // some case's have the same outcome if ($options['param'] == "page_parent") { $options['param'] = "page"; } switch ($options['param']) { case "post_type": // all post types except attachment $choices = apply_filters('spu/get_post_types', array(), array('attachment')); break; case "page": $post_type = 'page'; $args = array('posts_per_page' => -1, 'post_type' => $post_type, 'orderby' => 'menu_order title', 'order' => 'ASC', 'post_status' => 'any', 'suppress_filters' => false, 'update_post_meta_cache' => false); $posts = get_posts(apply_filters('spu/rules/page_args', $args)); if ($posts) { // sort into hierachial order! if (is_post_type_hierarchical($post_type)) { $posts = get_page_children(0, $posts); } foreach ($posts as $page) { $title = ''; $ancestors = get_ancestors($page->ID, 'page'); if ($ancestors) { foreach ($ancestors as $a) { $title .= '- '; } } $title .= apply_filters('the_title', $page->post_title, $page->ID); // status if ($page->post_status != "publish") { $title .= " ({$page->post_status})"; } $choices[$page->ID] = $title; } // foreach($pages as $page) } break; case "page_type": $choices = array('all_pages' => __("All Pages", 'popups'), 'front_page' => __("Front Page", 'popups'), 'posts_page' => __("Posts Page", 'popups'), 'category_page' => __("Category Page", 'popups'), 'search_page' => __("Search Page", 'popups'), 'archive_page' => __("Archives Page", 'popups'), 'top_level' => __("Top Level Page (parent of 0)", 'popups'), 'parent' => __("Parent Page (has children)", 'popups'), 'child' => __("Child Page (has parent)", 'popups')); break; case "page_template": $choices = array('default' => __("Default Template", 'popups')); $templates = get_page_templates(); foreach ($templates as $k => $v) { $choices[$v] = $k; } break; case "post": $post_types = get_post_types(); unset($post_types['page'], $post_types['attachment'], $post_types['revision'], $post_types['nav_menu_item'], $post_types['spucpt']); if ($post_types) { foreach ($post_types as $post_type) { $args = array('numberposts' => '-1', 'post_type' => $post_type, 'post_status' => array('publish', 'private', 'draft', 'inherit', 'future'), 'suppress_filters' => false); $posts = get_posts(apply_filters('spu/rules/post_args', $args)); if ($posts) { $choices[$post_type] = array(); foreach ($posts as $post) { $title = apply_filters('the_title', $post->post_title, $post->ID); // status if ($post->post_status != "publish") { $title .= " ({$post->post_status})"; } $choices[$post_type][$post->ID] = $title; } // foreach($posts as $post) } // if( $posts ) } // foreach( $post_types as $post_type ) } // if( $post_types ) break; case "post_category": $categories = get_terms('category', array('get' => 'all', 'fields' => 'id=>name')); $choices = apply_filters('spu/rules/categories', $categories); break; case "post_format": $choices = get_post_format_strings(); break; case "post_status": $choices = get_post_stati(); break; case "user_type": global $wp_roles; $choices = $wp_roles->get_names(); if (is_multisite()) { $choices['super_admin'] = __('Super Admin'); } break; case "taxonomy": $choices = array(); $simple_value = true; $choices = apply_filters('spu/get_taxonomies', $choices, $simple_value); break; case "logged_user": case "mobiles": case "tablets": case "left_comment": case "search_engine": case "same_site": $choices = array('true' => __('True', 'popups')); break; } // allow custom rules rules $choices = apply_filters('spu/rules/rule_values/' . $options['param'], $choices); // Custom fields for rules do_action('spu/rules/print_' . $options['param'] . '_field', $options, $choices); // ajax? if ($is_ajax) { die; } }
function getImages() { if (!$this->id) { return false; } ++$this->lazyLoad; $tempImages = get_post_meta($this->id, ROBO_GALLERY_PREFIX . 'galleryImages', true); if (isset($tempImages) && !is_array($tempImages) == 1 && trim($tempImages) == '') { $tempImages = array(); } if (!get_post_meta($this->id, ROBO_GALLERY_PREFIX . 'menuSelfImages', true)) { $tempImages = array(); } for ($i = 0; $i < count($tempImages); $i++) { $this->imgArray[] = array('id' => $tempImages[$i], 'catid' => $this->id); } $post = get_post($this->id); if (get_post_meta($this->id, ROBO_GALLERY_PREFIX . 'menuSelf', true)) { $this->catArray[] = array('id' => $this->id, 'title' => $post->post_title, 'name' => $post->post_name); } $my_wp_query = new WP_Query(); $all_wp_pages = $my_wp_query->query(array('post_type' => ROBO_GALLERY_TYPE_POST, 'orderby' => array('menu_order' => 'DESC', 'order' => 'ASC', 'title' => 'DESC'), 'posts_per_page' => $this->lazyLoad)); //print_r($all_wp_pages); $children = get_page_children($this->id, $all_wp_pages); //print_r($children); $tempCatArray = array(); for ($i = 0; $i < count($children); $i++) { $tempImages = get_post_meta($children[$i]->ID, ROBO_GALLERY_PREFIX . 'galleryImages', true); if ($tempImages && count($tempImages)) { $post = get_post($children[$i]->ID); $tempCatArray[] = array('id' => $children[$i]->ID, 'title' => $post->post_title, 'name' => $post->post_name); for ($j = 0; $j < count($tempImages); $j++) { $this->imgArray[] = array('id' => $tempImages[$j], 'catid' => $children[$i]->ID); } } } $tempCatArray = array_reverse($tempCatArray); $this->catArray = array_merge($this->catArray, $tempCatArray); for ($i = 0; $i < count($this->imgArray); $i++) { $img = $this->imgArray[$i]; $thumb = wp_get_attachment_image_src($img['id'], $this->thumbsource); $this->imgArray[$i]['image'] = wp_get_attachment_url($img['id']); $this->imgArray[$i]['thumb'] = isset($thumb) && count($thumb) ? $thumb[0] : ''; $this->imgArray[$i]['sizeW'] = isset($thumb[1]) && count($thumb) ? $thumb[1] : $this->width; $this->imgArray[$i]['sizeH'] = isset($thumb[2]) && count($thumb) ? $thumb[2] : $this->height; $this->imgArray[$i]['data'] = get_post($img['id']); $this->imgArray[$i]['link'] = get_post_meta($img['id'], ROBO_GALLERY_PREFIX . 'gallery_link', true); $this->imgArray[$i]['typelink'] = get_post_meta($img['id'], ROBO_GALLERY_PREFIX . 'gallery_type_link', true); $this->imgArray[$i]['videolink'] = get_post_meta($img['id'], ROBO_GALLERY_PREFIX . 'gallery_video_link', true); $this->imgArray[$i]['col'] = get_post_meta($img['id'], ROBO_GALLERY_PREFIX . 'gallery_col', true); $this->imgArray[$i]['effect'] = get_post_meta($img['id'], ROBO_GALLERY_PREFIX . 'gallery_effect', true); } switch ($this->orderby) { case 'random': shuffle($this->imgArray); break; case 'titleU': usort($this->imgArray, array('roboGalleryImages', 'titleUp')); break; case 'titleD': usort($this->imgArray, array('roboGalleryImages', 'titleDown')); break; case 'dateU': usort($this->imgArray, array('roboGalleryImages', 'dateUp')); break; case 'dateD': usort($this->imgArray, array('roboGalleryImages', 'dateDown')); break; case 'categoryU': $this->imgArray = array_reverse($this->imgArray); break; case 'categoryD': default: break; } }
/** * Retrieve a list of pages. * * The defaults that can be overridden are the following: 'child_of', * 'sort_order', 'sort_column', 'post_title', 'hierarchical', 'exclude', * 'include', 'meta_key', 'meta_value','authors', 'number', and 'offset'. * * @since 1.5.0 * @uses $wpdb * * @param mixed $args Optional. Array or string of options that overrides defaults. * @return array List of pages matching defaults or $args */ function get_pages($args = '') { global $wpdb; $pages = false; $defaults = array('child_of' => 0, 'sort_order' => 'ASC', 'sort_column' => 'post_title', 'hierarchical' => 1, 'exclude' => array(), 'include' => array(), 'meta_key' => '', 'meta_value' => '', 'authors' => '', 'parent' => -1, 'exclude_tree' => '', 'number' => '', 'offset' => 0, 'post_type' => 'page', 'post_status' => 'publish'); $r = wp_parse_args($args, $defaults); extract($r, EXTR_SKIP); $number = (int) $number; $offset = (int) $offset; // Make sure the post type is hierarchical $hierarchical_post_types = get_post_types(array('hierarchical' => true)); if (!in_array($post_type, $hierarchical_post_types)) { return $pages; } // Make sure we have a valid post status if (!is_array($post_status)) { $post_status = explode(',', $post_status); } if (array_diff($post_status, get_post_stati())) { return $pages; } $cache = array(); $key = md5(serialize(compact(array_keys($defaults)))); if ($cache = wp_cache_get('get_pages', 'posts')) { if (is_array($cache) && isset($cache[$key]) && is_array($cache[$key])) { // Convert to WP_Post instances $pages = array_map('get_post', $cache[$key]); $pages = apply_filters('get_pages', $pages, $r); return $pages; } } if (!is_array($cache)) { $cache = array(); } $inclusions = ''; if (!empty($include)) { $child_of = 0; //ignore child_of, parent, exclude, meta_key, and meta_value params if using include $parent = -1; $exclude = ''; $meta_key = ''; $meta_value = ''; $hierarchical = false; $incpages = wp_parse_id_list($include); if (!empty($incpages)) { foreach ($incpages as $incpage) { if (empty($inclusions)) { $inclusions = $wpdb->prepare(' AND ( ID = %d ', $incpage); } else { $inclusions .= $wpdb->prepare(' OR ID = %d ', $incpage); } } } } if (!empty($inclusions)) { $inclusions .= ')'; } $exclusions = ''; if (!empty($exclude)) { $expages = wp_parse_id_list($exclude); if (!empty($expages)) { foreach ($expages as $expage) { if (empty($exclusions)) { $exclusions = $wpdb->prepare(' AND ( ID <> %d ', $expage); } else { $exclusions .= $wpdb->prepare(' AND ID <> %d ', $expage); } } } } if (!empty($exclusions)) { $exclusions .= ')'; } $author_query = ''; if (!empty($authors)) { $post_authors = preg_split('/[\\s,]+/', $authors); if (!empty($post_authors)) { foreach ($post_authors as $post_author) { //Do we have an author id or an author login? if (0 == intval($post_author)) { $post_author = get_user_by('login', $post_author); if (empty($post_author)) { continue; } if (empty($post_author->ID)) { continue; } $post_author = $post_author->ID; } if ('' == $author_query) { $author_query = $wpdb->prepare(' post_author = %d ', $post_author); } else { $author_query .= $wpdb->prepare(' OR post_author = %d ', $post_author); } } if ('' != $author_query) { $author_query = " AND ({$author_query})"; } } } $join = ''; $where = "{$exclusions} {$inclusions} "; if (!empty($meta_key) || !empty($meta_value)) { $join = " LEFT JOIN {$wpdb->postmeta} ON ( {$wpdb->posts}.ID = {$wpdb->postmeta}.post_id )"; // meta_key and meta_value might be slashed $meta_key = stripslashes($meta_key); $meta_value = stripslashes($meta_value); if (!empty($meta_key)) { $where .= $wpdb->prepare(" AND {$wpdb->postmeta}.meta_key = %s", $meta_key); } if (!empty($meta_value)) { $where .= $wpdb->prepare(" AND {$wpdb->postmeta}.meta_value = %s", $meta_value); } } if ($parent >= 0) { $where .= $wpdb->prepare(' AND post_parent = %d ', $parent); } if (1 == count($post_status)) { $where_post_type = $wpdb->prepare("post_type = %s AND post_status = %s", $post_type, array_shift($post_status)); } else { $post_status = implode("', '", $post_status); $where_post_type = $wpdb->prepare("post_type = %s AND post_status IN ('{$post_status}')", $post_type); } $orderby_array = array(); $allowed_keys = array('author', 'post_author', 'date', 'post_date', 'title', 'post_title', 'name', 'post_name', 'modified', 'post_modified', 'modified_gmt', 'post_modified_gmt', 'menu_order', 'parent', 'post_parent', 'ID', 'rand', 'comment_count'); foreach (explode(',', $sort_column) as $orderby) { $orderby = trim($orderby); if (!in_array($orderby, $allowed_keys)) { continue; } switch ($orderby) { case 'menu_order': break; case 'ID': $orderby = "{$wpdb->posts}.ID"; break; case 'rand': $orderby = 'RAND()'; break; case 'comment_count': $orderby = "{$wpdb->posts}.comment_count"; break; default: if (0 === strpos($orderby, 'post_')) { $orderby = "{$wpdb->posts}." . $orderby; } else { $orderby = "{$wpdb->posts}.post_" . $orderby; } } $orderby_array[] = $orderby; } $sort_column = !empty($orderby_array) ? implode(',', $orderby_array) : "{$wpdb->posts}.post_title"; $sort_order = strtoupper($sort_order); if ('' !== $sort_order && !in_array($sort_order, array('ASC', 'DESC'))) { $sort_order = 'ASC'; } $query = "SELECT * FROM {$wpdb->posts} {$join} WHERE ({$where_post_type}) {$where} "; $query .= $author_query; $query .= " ORDER BY " . $sort_column . " " . $sort_order; if (!empty($number)) { $query .= ' LIMIT ' . $offset . ',' . $number; } $pages = $wpdb->get_results($query); if (empty($pages)) { $pages = apply_filters('get_pages', array(), $r); return $pages; } // Sanitize before caching so it'll only get done once $num_pages = count($pages); for ($i = 0; $i < $num_pages; $i++) { $pages[$i] = sanitize_post($pages[$i], 'raw'); } // Update cache. update_post_cache($pages); if ($child_of || $hierarchical) { $pages = get_page_children($child_of, $pages); } if (!empty($exclude_tree)) { $exclude = (int) $exclude_tree; $children = get_page_children($exclude, $pages); $excludes = array(); foreach ($children as $child) { $excludes[] = $child->ID; } $excludes[] = $exclude; $num_pages = count($pages); for ($i = 0; $i < $num_pages; $i++) { if (in_array($pages[$i]->ID, $excludes)) { unset($pages[$i]); } } } $cache[$key] = $pages; wp_cache_set('get_pages', $cache, 'posts'); // Convert to WP_Post instances $pages = array_map('get_post', $pages); $pages = apply_filters('get_pages', $pages, $r); return $pages; }
function ajax_render_location($options = array()) { // defaults $defaults = array('group_id' => 0, 'rule_id' => 0, 'value' => null, 'param' => null); $is_ajax = false; if (isset($_POST['nonce']) && wp_verify_nonce($_POST['nonce'], 'acf_nonce')) { $is_ajax = true; } // Is AJAX call? if ($is_ajax) { $options = array_merge($defaults, $_POST); } else { $options = array_merge($defaults, $options); } // vars $choices = array(); // some case's have the same outcome if ($options['param'] == "page_parent") { $options['param'] = "page"; } switch ($options['param']) { case "post_type": // all post types except attachment $choices = apply_filters('acf/get_post_types', array(), array('attachment')); break; case "page": $post_type = 'page'; $posts = get_posts(array('posts_per_page' => -1, 'post_type' => $post_type, 'orderby' => 'menu_order title', 'order' => 'ASC', 'post_status' => 'any', 'suppress_filters' => false, 'update_post_meta_cache' => false)); if ($posts) { // sort into hierachial order! if (is_post_type_hierarchical($post_type)) { $posts = get_page_children(0, $posts); } foreach ($posts as $page) { $title = ''; $ancestors = get_ancestors($page->ID, 'page'); if ($ancestors) { foreach ($ancestors as $a) { $title .= '- '; } } $title .= apply_filters('the_title', $page->post_title, $page->ID); // status if ($page->post_status != "publish") { $title .= " ({$page->post_status})"; } $choices[$page->ID] = $title; } // foreach($pages as $page) } break; case "page_type": $choices = array('front_page' => __("Front Page", 'acf'), 'posts_page' => __("Posts Page", 'acf'), 'top_level' => __("Top Level Page (parent of 0)", 'acf'), 'parent' => __("Parent Page (has children)", 'acf'), 'child' => __("Child Page (has parent)", 'acf')); break; case "page_template": $choices = array('default' => __("Default Template", 'acf')); $templates = get_page_templates(); foreach ($templates as $k => $v) { $choices[$v] = $k; } break; case "post": $post_types = get_post_types(); unset($post_types['page'], $post_types['attachment'], $post_types['revision'], $post_types['nav_menu_item'], $post_types['acf']); if ($post_types) { foreach ($post_types as $post_type) { $posts = get_posts(array('numberposts' => '-1', 'post_type' => $post_type, 'post_status' => array('publish', 'private', 'draft', 'inherit', 'future'), 'suppress_filters' => false)); if ($posts) { $choices[$post_type] = array(); foreach ($posts as $post) { $title = apply_filters('the_title', $post->post_title, $post->ID); // status if ($post->post_status != "publish") { $title .= " ({$post->post_status})"; } $choices[$post_type][$post->ID] = $title; } // foreach($posts as $post) } // if( $posts ) } // foreach( $post_types as $post_type ) } // if( $post_types ) break; case "post_category": $category_ids = get_all_category_ids(); foreach ($category_ids as $cat_id) { $cat_name = get_cat_name($cat_id); $choices[$cat_id] = $cat_name; } break; case "post_format": $choices = get_post_format_strings(); break; case "post_status": $choices = array('publish' => __('Publish', 'acf'), 'pending' => __('Pending Review', 'acf'), 'draft' => __('Draft', 'acf'), 'future' => __('Future', 'acf'), 'private' => __('Private', 'acf'), 'inherit' => __('Revision', 'acf'), 'trash' => __('Trash', 'acf')); break; case "user_type": global $wp_roles; $choices = $wp_roles->get_names(); if (is_multisite()) { $choices['super_admin'] = __('Super Admin', 'acf'); } break; case "taxonomy": $choices = array(); $simple_value = true; $choices = apply_filters('acf/get_taxonomies_for_select', $choices, $simple_value); break; case "ef_taxonomy": $choices = array('all' => __('All', 'acf')); $taxonomies = get_taxonomies(array('public' => true), 'objects'); foreach ($taxonomies as $taxonomy) { $choices[$taxonomy->name] = $taxonomy->labels->name; } // unset post_format (why is this a public taxonomy?) if (isset($choices['post_format'])) { unset($choices['post_format']); } break; case "ef_user": global $wp_roles; $choices = array_merge(array('all' => __('All', 'acf')), $wp_roles->get_names()); break; case "ef_media": $choices = array('all' => __('All', 'acf')); break; } // allow custom location rules $choices = apply_filters('acf/location/rule_values/' . $options['param'], $choices); // create field do_action('acf/create_field', array('type' => 'select', 'name' => 'location[' . $options['group_id'] . '][' . $options['rule_id'] . '][value]', 'value' => $options['value'], 'choices' => $choices)); // ajax? if ($is_ajax) { die; } }
/** * Prints the box content. * * @param WP_Post $post The object for the current post/page. */ function mf_inner_location_box($post) { $faires = array(); $faire_location = array(); if (isset($_POST['nonce']) && !wp_verify_nonce($_POST['nonce'])) { // Add an nonce field so we can check for it later. wp_nonce_field('mf_inner_location_box', 'mf_inner_location_box_nonce'); // Get all of the faires. $terms = $_POST['faire']; // Loop through the faires, and get all of the foreach ($terms as $faire) { // Need to attach the entire term object to this... $faires[$faire] = get_term(absint($faire), 'faire'); } } if ($post) { // Add an nonce field so we can check for it later. wp_nonce_field('mf_inner_location_box', 'mf_inner_location_box_nonce'); $faire_location_meta = get_post_meta($post->ID, 'faire_location', true); $faire_location = is_array($faire_location_meta) ? $faire_location_meta : array(); $faires = get_the_terms($post, 'faire'); } // Since we have a few, loop through, and get all of the results. if ($faires) { $faire = array(); foreach ($faires as $da_faire) { $faire[] = sanitize_title($da_faire->slug); } // WP_Query arguments $args = array('post_type' => 'location', 'posts_per_page' => 200, 'order' => 'ASC', 'orderby' => 'title', 'tax_query' => array(array('taxonomy' => 'faire', 'field' => 'slug', 'terms' => $faire))); // The Query $query = new WP_Query($args); echo '<ul class="style="-moz-column-count:3;-moz-column-gap:20px;-webkit-column-count:3;-webkit-column-gap:20px;">'; // Build the interface. foreach ($query->posts as $location) { // Display only the parent elements first. // If the parent has children, we'll handle that below if ($location->post_parent == 0) { echo '<li style="-moz-column-count:3;-moz-column-gap:20px;-webkit-column-count:3;-webkit-column-gap:20px;"><label class="checkbox">'; if (in_array($location->ID, $faire_location)) { echo '<input type="checkbox" name="location[]" value="' . absint($location->ID) . '" checked>'; } else { echo '<input type="checkbox" name="location[]" value="' . absint($location->ID) . '">'; } echo wp_kses_post($location->post_title); echo '</label">'; // Extract the children if they exist $children = get_page_children(absint($location->ID), $query->posts); if (!empty($children)) { echo '<ul>'; foreach ($children as $child_loc) { echo '<li> <strong>—</strong> <label class="checkbox">'; if (in_array($child_loc->ID, $faire_location)) { echo '<input type="checkbox" name="location[]" value="' . absint($child_loc->ID) . '" checked>'; } else { echo '<input type="checkbox" name="location[]" value="' . absint($child_loc->ID) . '">'; } echo wp_kses_post($child_loc->post_title); echo '</label></li>'; } echo '</ul></li>'; } else { echo '</li>'; } } } echo '</ul>'; } else { echo 'You don\'t have a location created for this event yet. Add one, and the appropriate locations will be added.'; } // Add new locations echo '<p><a class="button" target="_blank" href="' . esc_url(admin_url('post-new.php?post_type=location')) . '">Add a New Location</a><p>'; }
function scoper_get_page_descendant_ids($page_id, $pages = '') { global $wpdb; if (empty($pages)) { $pages = scoper_get_results("SELECT ID, post_parent FROM {$wpdb->posts} WHERE post_parent > 0 AND post_type NOT IN ( 'revision', 'attachment' )"); } $descendant_ids = array(); foreach ((array) $pages as $page) { if ($page->post_parent == $page_id) { $descendant_ids[] = $page->ID; if ($children = get_page_children($page->ID, $pages)) { foreach ($children as $_page) { $descendant_ids[] = $_page->ID; } } } } return $descendant_ids; }
function acf_get_posts($args) { // vars $r = array(); // defaults $args = acf_parse_args($args, array('posts_per_page' => -1, 'post_type' => 'post', 'orderby' => 'menu_order title', 'order' => 'ASC', 'post_status' => 'any', 'suppress_filters' => false, 'update_post_meta_cache' => false)); // find array of post_type $post_types = acf_force_type_array($args['post_type']); // attachment doesn't work if it is the only item in an array if (count($post_types) == 1) { $args['post_type'] = current($post_types); } // get posts $posts = get_posts($args); // loop foreach ($post_types as $post_type) { // vars $this_posts = array(); $this_group = array(); // populate $this_posts foreach (array_keys($posts) as $key) { if ($posts[$key]->post_type == $post_type) { $this_posts[] = acf_extract_var($posts, $key); } } // bail early if no posts for this post type if (empty($this_posts)) { continue; } // sort into hierachial order! if (is_post_type_hierarchical($post_type)) { // this will fail if a search has taken place because parents wont exist if (empty($args['s'])) { $this_posts = get_page_children(0, $this_posts); } } // populate $this_posts foreach (array_keys($this_posts) as $key) { // extract post $post = acf_extract_var($this_posts, $key); // add to group $this_group[$post->ID] = $post; } // group by post type $post_type_object = get_post_type_object($post_type); $post_type_name = $post_type_object->labels->name; $r[$post_type_name] = $this_group; } // return return $r; }
<?php if ($header) { echo '<h2 class="clinics-header">' . $header . '</h2>'; } ?> <img src="<?php the_sub_field('background_image'); ?> " alt="Uk Map"> <?php $post_ID = get_sub_field('clinics'); $clinics_query = new WP_Query(); $pages = $clinics_query->query(array('post_type' => 'page', 'posts_per_page' => -1)); $clinics = get_page_children($post_ID, $pages); ?> <ul class="clinics-list"> <?php foreach ($clinics as $post) { // variable must be called $post (IMPORTANT) ?> <?php setup_postdata($post); ?> <li> <a href="<?php the_permalink(); ?> " title="<?php
* * * */ $user = wp_get_current_user(); /*if($user->ID==0){ wp_redirect('/'); }*/ get_header(); if (have_posts()) { the_post(); } $query = new WP_Query(); $arg = array('sort_order' => 'asc', 'sort_column' => 'post_title', 'hierarchical' => 1, 'parent' => get_the_ID(), 'offset' => 0, 'post_type' => 'page', 'post_status' => 'publish'); $all_pages = get_pages($args); $pages = get_page_children(get_the_ID(), $all_pages); ?> <div class="content-wap"> <div class="db-mx-erg-iden iden-xmg-al"> <div class="container"> <div class="row sqs-row"> <?php $classes = array('lix', 'lxce', 'lrg'); foreach ($pages as $k => $p) { ?> <div class="col sqs-col-4 span-4"> <div class="con-la-xm <?php echo isset($classes[$k]) ? $classes[$k] : ''; ?>
function &get_pages($args = '') { global $wpdb; if ( is_array($args) ) $r = &$args; else parse_str($args, $r); $defaults = array('child_of' => 0, 'sort_order' => 'ASC', 'sort_column' => 'post_title', 'hierarchical' => 1, 'exclude' => '', 'include' => '', 'meta_key' => '', 'meta_value' => '', 'authors' => ''); $r = array_merge($defaults, $r); extract($r); $key = md5( serialize( $r ) ); if ( $cache = wp_cache_get( 'get_pages', 'page' ) ) if ( isset( $cache[ $key ] ) ) return apply_filters('get_pages', $cache[ $key ], $r ); $inclusions = ''; if ( !empty($include) ) { $child_of = 0; //ignore child_of, exclude, meta_key, and meta_value params if using include $exclude = ''; $meta_key = ''; $meta_value = ''; $incpages = preg_split('/[\s,]+/',$include); if ( count($incpages) ) { foreach ( $incpages as $incpage ) { if (empty($inclusions)) $inclusions = ' AND ( ID = ' . intval($incpage) . ' '; else $inclusions .= ' OR ID = ' . intval($incpage) . ' '; } } } if (!empty($inclusions)) $inclusions .= ')'; $exclusions = ''; if ( !empty($exclude) ) { $expages = preg_split('/[\s,]+/',$exclude); if ( count($expages) ) { foreach ( $expages as $expage ) { if (empty($exclusions)) $exclusions = ' AND ( ID <> ' . intval($expage) . ' '; else $exclusions .= ' AND ID <> ' . intval($expage) . ' '; } } } if (!empty($exclusions)) $exclusions .= ')'; $author_query = ''; if (!empty($authors)) { $post_authors = preg_split('/[\s,]+/',$authors); if ( count($post_authors) ) { foreach ( $post_authors as $post_author ) { //Do we have an author id or an author login? if ( 0 == intval($post_author) ) { $post_author = get_userdatabylogin($post_author); if ( empty($post_author) ) continue; if ( empty($post_author->ID) ) continue; $post_author = $post_author->ID; } if ( '' == $author_query ) $author_query = ' post_author = ' . intval($post_author) . ' '; else $author_query .= ' OR post_author = ' . intval($post_author) . ' '; } if ( '' != $author_query ) $author_query = " AND ($author_query)"; } } $query = "SELECT * FROM $wpdb->posts " ; $query .= ( empty( $meta_key ) ? "" : ", $wpdb->postmeta " ) ; $query .= " WHERE (post_type = 'page' AND post_status = 'publish') $exclusions $inclusions " ; $query .= ( empty( $meta_key ) | empty($meta_value) ? "" : " AND ($wpdb->posts.ID = $wpdb->postmeta.post_id AND $wpdb->postmeta.meta_key = '$meta_key' AND $wpdb->postmeta.meta_value = '$meta_value' )" ) ; $query .= $author_query; $query .= " ORDER BY " . $sort_column . " " . $sort_order ; $pages = $wpdb->get_results($query); $pages = apply_filters('get_pages', $pages, $r); if ( empty($pages) ) return array(); // Update cache. update_page_cache($pages); if ( $child_of || $hierarchical ) $pages = & get_page_children($child_of, $pages); $cache[ $key ] = $pages; wp_cache_set( 'get_pages', $cache, 'page' ); return $pages; }
if ($page->post_parent == '0') { ?> <li> <a href="<?php echo get_page_link($page->ID); ?> "><strong><?php echo $page->post_title; ?> </strong><span> <?php echo get_post_meta($page->ID, "subtitle", true); ?> </span></a> <?php $child_pages = get_pages('child_of=' . $page->ID); if (get_page_children($page->ID, $child_pages)) { ?> <ul><?php wp_list_pages('title_li=&child_of=' . $page->ID); ?> </ul> <?php } ?> </li> <?php } } ?> </ul> <?php
/** * get_pages() - Retrieve a list of pages * * {@internal Missing Long Description}} * * @package WordPress * @subpackage Post * @since 1.5 * @uses $wpdb * * @param mixed $args Optional. Array or string of options * @return array List of pages matching defaults or $args */ function &get_pages($args = '') { global $wpdb; $defaults = array('child_of' => 0, 'sort_order' => 'ASC', 'sort_column' => 'post_title', 'hierarchical' => 1, 'exclude' => '', 'include' => '', 'meta_key' => '', 'meta_value' => '', 'authors' => ''); $r = wp_parse_args($args, $defaults); extract($r, EXTR_SKIP); $key = md5(serialize($r)); if ($cache = wp_cache_get('get_pages', 'posts')) { if (isset($cache[$key])) { return apply_filters('get_pages', $cache[$key], $r); } } $inclusions = ''; if (!empty($include)) { $child_of = 0; //ignore child_of, exclude, meta_key, and meta_value params if using include $exclude = ''; $meta_key = ''; $meta_value = ''; $hierarchical = false; $incpages = preg_split('/[\\s,]+/', $include); if (count($incpages)) { foreach ($incpages as $incpage) { if (empty($inclusions)) { $inclusions = $wpdb->prepare(' AND ( ID = %d ', $incpage); } else { $inclusions .= $wpdb->prepare(' OR ID = %d ', $incpage); } } } } if (!empty($inclusions)) { $inclusions .= ')'; } $exclusions = ''; if (!empty($exclude)) { $expages = preg_split('/[\\s,]+/', $exclude); if (count($expages)) { foreach ($expages as $expage) { if (empty($exclusions)) { $exclusions = $wpdb->prepare(' AND ( ID <> %d ', $expage); } else { $exclusions .= $wpdb->prepare(' AND ID <> %d ', $expage); } } } } if (!empty($exclusions)) { $exclusions .= ')'; } $author_query = ''; if (!empty($authors)) { $post_authors = preg_split('/[\\s,]+/', $authors); if (count($post_authors)) { foreach ($post_authors as $post_author) { //Do we have an author id or an author login? if (0 == intval($post_author)) { $post_author = get_userdatabylogin($post_author); if (empty($post_author)) { continue; } if (empty($post_author->ID)) { continue; } $post_author = $post_author->ID; } if ('' == $author_query) { $author_query = $wpdb->prepare(' post_author = %d ', $post_author); } else { $author_query .= $wpdb->prepare(' OR post_author = %d ', $post_author); } } if ('' != $author_query) { $author_query = " AND ({$author_query})"; } } } $query = "SELECT * FROM {$wpdb->posts} "; $query .= empty($meta_key) ? "" : ", {$wpdb->postmeta} "; $query .= " WHERE (post_type = 'page' AND post_status = 'publish') {$exclusions} {$inclusions} "; // expected_slashed ($meta_key, $meta_value) -- also, it looks funky $query .= empty($meta_key) | empty($meta_value) ? "" : " AND ({$wpdb->posts}.ID = {$wpdb->postmeta}.post_id AND {$wpdb->postmeta}.meta_key = '{$meta_key}' AND {$wpdb->postmeta}.meta_value = '{$meta_value}' )"; $query .= $author_query; $query .= " ORDER BY " . $sort_column . " " . $sort_order; $pages = $wpdb->get_results($query); if (empty($pages)) { return apply_filters('get_pages', array(), $r); } // Update cache. update_page_cache($pages); if ($child_of || $hierarchical) { $pages =& get_page_children($child_of, $pages); } $cache[$key] = $pages; wp_cache_set('get_pages', $cache, 'posts'); $pages = apply_filters('get_pages', $pages, $r); return $pages; }
/** * get_pages() - Retrieve a list of pages * * {@internal Missing Long Description}} * * @package WordPress * @subpackage Post * @since 1.5 * @uses $wpdb * * @param mixed $args Optional. Array or string of options * @return array List of pages matching defaults or $args */ function &get_pages($args = '') { global $wpdb; $defaults = array( 'child_of' => 0, 'sort_order' => 'ASC', 'sort_column' => 'post_title', 'hierarchical' => 1, 'exclude' => '', 'include' => '', 'meta_key' => '', 'meta_value' => '', 'authors' => '' ); $r = wp_parse_args( $args, $defaults ); extract( $r, EXTR_SKIP ); $key = md5( serialize( $r ) ); if ( $cache = wp_cache_get( 'get_pages', 'posts' ) ) if ( isset( $cache[ $key ] ) ) return apply_filters('get_pages', $cache[ $key ], $r ); $inclusions = ''; if ( !empty($include) ) { $child_of = 0; //ignore child_of, exclude, meta_key, and meta_value params if using include $exclude = ''; $meta_key = ''; $meta_value = ''; $hierarchical = false; $incpages = preg_split('/[\s,]+/',$include); if ( count($incpages) ) { foreach ( $incpages as $incpage ) { if (empty($inclusions)) $inclusions = $wpdb->prepare(' AND ( ID = %d ', $incpage); else $inclusions .= $wpdb->prepare(' OR ID = %d ', $incpage); } } } if (!empty($inclusions)) $inclusions .= ')'; $exclusions = ''; if ( !empty($exclude) ) { $expages = preg_split('/[\s,]+/',$exclude); if ( count($expages) ) { foreach ( $expages as $expage ) { if (empty($exclusions)) $exclusions = $wpdb->prepare(' AND ( ID <> %d ', $expage); else $exclusions .= $wpdb->prepare(' AND ID <> %d ', $expage); } } } if (!empty($exclusions)) $exclusions .= ')'; $author_query = ''; if (!empty($authors)) { $post_authors = preg_split('/[\s,]+/',$authors); if ( count($post_authors) ) { foreach ( $post_authors as $post_author ) { //Do we have an author id or an author login? if ( 0 == intval($post_author) ) { $post_author = get_userdatabylogin($post_author); if ( empty($post_author) ) continue; if ( empty($post_author->ID) ) continue; $post_author = $post_author->ID; } if ( '' == $author_query ) $author_query = $wpdb->prepare(' post_author = %d ', $post_author); else $author_query .= $wpdb->prepare(' OR post_author = %d ', $post_author); } if ( '' != $author_query ) $author_query = " AND ($author_query)"; } } $join = ''; $where = "$exclusions $inclusions "; if ( ! empty( $meta_key ) || ! empty( $meta_value ) ) { $join = " LEFT JOIN $wpdb->postmeta ON ( $wpdb->posts.ID = $wpdb->postmeta.post_id )"; // meta_key and met_value might be slashed $meta_key = stripslashes($meta_key); $meta_value = stripslashes($meta_value); if ( ! empty( $meta_key ) ) $where .= $wpdb->prepare(" AND $wpdb->postmeta.meta_key = %s", $meta_key); if ( ! empty( $meta_value ) ) $where .= $wpdb->prepare(" AND $wpdb->postmeta.meta_value = %s", $meta_value); } $query = "SELECT * FROM $wpdb->posts $join WHERE (post_type = 'page' AND post_status = 'publish') $where "; $query .= $author_query; $query .= " ORDER BY " . $sort_column . " " . $sort_order ; $pages = $wpdb->get_results($query); if ( empty($pages) ) return apply_filters('get_pages', array(), $r); // Update cache. update_page_cache($pages); if ( $child_of || $hierarchical ) $pages = & get_page_children($child_of, $pages); $cache[ $key ] = $pages; wp_cache_set( 'get_pages', $cache, 'posts' ); $pages = apply_filters('get_pages', $pages, $r); return $pages; }
<?php /* Title: Accessories Post Type: product Order: 60 Collapse: true Priority: high */ $choices_array = array('' => '-- Select Accessories -- '); $my_wp_query = new WP_Query(); $all_wp_pages = $my_wp_query->query(array('post_type' => 'page', 'posts_per_page' => 500)); $accessories = get_page_children(9, $all_wp_pages); foreach ($accessories as $accessory) { $choices_array[$accessory->ID] = $accessory->post_title; } piklist('field', ['type' => 'group', 'field' => 'accessories-group', 'description' => __('After you\'ve created a list of accessories, you can drag and drop to reorder them.'), 'add_more' => true, 'fields' => [['type' => 'select', 'label' => __('Add Accessory'), 'field' => 'accessories-product', 'choices' => $choices_array]]]);
function widget($args, $instance) { extract($args); $title = apply_filters('widget_title', $instance['title']); $show_modified_date = $instance['show_modified_date']; $show_published_date = $instance['show_published_date']; $show_author = $instance['show_author']; $showabout = false; if (is_single()) { $showabout = true; } if (is_singular(array('forum', 'topic', 'reply'))) { $showabout = false; } if (is_page()) { $acf_key = "widget_" . $this->id_base . "-" . $this->number . "_about_this_page_children"; $aboutChildren = get_option($acf_key); global $post; $my_wp_query = new WP_Query(); $all_wp_pages = $my_wp_query->query(array('post_type' => 'page', 'posts_per_page' => -1)); if ($aboutChildren) { foreach ($aboutChildren as $a) { // Filter through all pages and find Portfolio's children $children = get_page_children($a, $all_wp_pages); if ($children) { foreach ($children as $c) { $child[] = $c->ID; if ($post->ID == $c->ID) { $showabout = true; } } } } } } if ($showabout) { echo $before_widget; echo "<div id='about-this-widget'>"; if ($title) { echo $before_title . $title . $after_title; } $tzone = get_option('timezone_string'); date_default_timezone_set($tzone); if ($show_modified_date == 'on') { $sdate = human_time_diff_plus(get_the_modified_time('U')); if ($sdate == "0 mins") { $sdate = " " . __("just now", "govintranet"); } else { $sdate = sprintf(__('%s ago', 'govintranet'), $sdate); } echo __('Updated', 'govintranet') . " <time datetime='" . $sdate . "'>" . $sdate . "</time><br>"; } if ($show_published_date == 'on') { $sdate = date(get_option('date_format'), strtotime(get_the_date())); $sdate = human_time_diff_plus(get_the_time('U')); if ($sdate == "0 mins") { $sdate = " " . __("just now", "govintranet"); } else { $sdate = sprintf(__('%s ago', 'govintranet'), $sdate); } echo __('Published', 'govintranet') . " <time datetime='" . $sdate . "'>" . $sdate . "</time><br>"; } if ($show_author == 'on') { $useremail = get_the_author_meta('user_email'); echo "<a href='mailto:" . $useremail . "'>"; the_author(); echo "</a>"; } echo "</div>"; echo $after_widget; } }
function flt_get_pages($results, $args = array()) { $results = (array) $results; global $wpdb; // === BEGIN Role Scoper ADDITION: global var; various special case exemption checks === // global $scoper, $current_rs_user; // need to skip cache retrieval if QTranslate is filtering get_pages with a priority of 1 or less $no_cache = !defined('SCOPER_QTRANSLATE_COMPAT') && awp_is_plugin_active('qtranslate'); // buffer titles in case they were filtered previously $titles = scoper_get_property_array($results, 'ID', 'post_title'); // depth is not really a get_pages arg, but remap exclude arg to exclude_tree if wp_list_terms called with depth=1 if (!empty($args['exclude']) && empty($args['exclude_tree']) && !empty($args['depth']) && 1 == $args['depth']) { if (0 !== strpos($args['exclude'], ',')) { // work around wp_list_pages() bug of attaching leading comma if a plugin uses wp_list_pages_excludes filter $args['exclude_tree'] = $args['exclude']; } } // // === END Role Scoper ADDITION === // ================================= $defaults = array('child_of' => 0, 'sort_order' => 'ASC', 'sort_column' => 'post_title', 'hierarchical' => 1, 'exclude' => array(), 'include' => array(), 'meta_key' => '', 'meta_value' => '', 'authors' => '', 'parent' => -1, 'exclude_tree' => '', 'number' => '', 'offset' => 0, 'post_type' => 'page', 'post_status' => 'publish', 'depth' => 0, 'suppress_filters' => 0, 'remap_parents' => -1, 'enforce_actual_depth' => -1, 'remap_thru_excluded_parent' => -1); // Role Scoper arguments added above // === BEGIN Role Scoper ADDITION: support front-end optimization $post_type = isset($args['post_type']) ? $args['post_type'] : $defaults['post_type']; $use_post_types = (array) scoper_get_option('use_post_types'); if (empty($use_post_types[$post_type])) { return $results; } if ($scoper->is_front()) { if ('page' == $post_type && defined('SCOPER_GET_PAGES_LEAN')) { // custom types are likely to have custom fields $defaults['fields'] = "{$wpdb->posts}.ID, {$wpdb->posts}.post_title, {$wpdb->posts}.post_parent, {$wpdb->posts}.post_date, {$wpdb->posts}.post_date_gmt, {$wpdb->posts}.post_status, {$wpdb->posts}.post_name, {$wpdb->posts}.post_modified, {$wpdb->posts}.post_modified_gmt, {$wpdb->posts}.guid, {$wpdb->posts}.menu_order, {$wpdb->posts}.comment_count"; } else { $defaults['fields'] = "{$wpdb->posts}.*"; if (!defined('SCOPER_FORCE_PAGES_CACHE')) { $no_cache = true; } // serialization / unserialization of post_content for all pages is too memory-intensive for sites with a lot of pages } } else { // required for xmlrpc getpagelist method $defaults['fields'] = "{$wpdb->posts}.*"; if (!defined('SCOPER_FORCE_PAGES_CACHE')) { $no_cache = true; } } // === END Role Scoper MODIFICATION === $r = wp_parse_args($args, $defaults); extract($r, EXTR_SKIP); $number = (int) $number; $offset = (int) $offset; $child_of = (int) $child_of; // Role Scoper modification: null value will confuse children array check // Make sure the post type is hierarchical $hierarchical_post_types = get_post_types(array('public' => true, 'hierarchical' => true)); if (!in_array($post_type, $hierarchical_post_types)) { return $results; } // Make sure we have a valid post status if (!in_array($post_status, get_post_stati())) { return $results; } // for the page parent dropdown, return no available selections for a published main page if the logged user isn't allowed to de-associate it from Main if (!empty($name) && 'parent_id' == $name) { global $post; if (!$post->post_parent && !$GLOBALS['scoper_admin_filters']->user_can_associate_main($post_type)) { $status_obj = get_post_status_object($post->post_status); if ($status_obj->public || $status_obj->private) { return array(); } } if (!empty($post) && $post_type == $post->post_type) { if ($post->post_parent) { $append_page = get_post($post->post_parent); } $exclude_tree = $post->ID; } } //$scoper->last_get_pages_args = $r; // don't copy entire args array unless it proves necessary $scoper->last_get_pages_depth = $depth; $scoper->last_get_pages_suppress_filters = $suppress_filters; if ($suppress_filters) { return $results; } // === BEGIN Role Scoper MODIFICATION: wp-cache key and flag specific to access type and user/groups // if (!scoper_get_otype_option('use_object_roles', 'post', $post_type)) { return $results; } $key = md5(serialize(compact(array_keys($defaults)))); $ckey = md5($key . CURRENT_ACCESS_NAME_RS); $cache_flag = 'rs_get_pages'; $cache = $current_rs_user->cache_get($cache_flag); if (false !== $cache) { if (!is_array($cache)) { $cache = array(); } if (!$no_cache && isset($cache[$ckey])) { // alternate filter name (WP core already applied get_pages filter) return apply_filters('get_pages_rs', $cache[$ckey], $r); } } // // === END Role Scoper MODIFICATION === // ==================================== $inclusions = ''; if (!empty($include)) { $child_of = 0; //ignore child_of, parent, exclude, meta_key, and meta_value params if using include $parent = -1; $exclude = ''; $meta_key = ''; $meta_value = ''; $hierarchical = false; $incpages = wp_parse_id_list($include); if (!empty($incpages)) { foreach ($incpages as $incpage) { if (empty($inclusions)) { $inclusions = ' AND ( ID = ' . intval($incpage) . ' '; } else { $inclusions .= ' OR ID = ' . intval($incpage) . ' '; } } } } if (!empty($inclusions)) { $inclusions .= ')'; } $exclusions = ''; if (!empty($exclude)) { $expages = wp_parse_id_list($exclude); if (!empty($expages)) { foreach ($expages as $expage) { if (empty($exclusions)) { $exclusions = ' AND ( ID <> ' . intval($expage) . ' '; } else { $exclusions .= ' AND ID <> ' . intval($expage) . ' '; } } } } if (!empty($exclusions)) { $exclusions .= ')'; } $author_query = ''; if (!empty($authors)) { $post_authors = wp_parse_id_list($authors); if (!empty($post_authors)) { foreach ($post_authors as $post_author) { //Do we have an author id or an author login? if (0 == intval($post_author)) { $post_author = get_userdatabylogin($post_author); if (empty($post_author)) { continue; } if (empty($post_author->ID)) { continue; } $post_author = $post_author->ID; } if ('' == $author_query) { $author_query = ' post_author = ' . intval($post_author) . ' '; } else { $author_query .= ' OR post_author = ' . intval($post_author) . ' '; } } if ('' != $author_query) { $author_query = " AND ({$author_query})"; } } } $join = ''; $where = "{$exclusions} {$inclusions} "; if (!empty($meta_key) || !empty($meta_value)) { $join = " INNER JOIN {$wpdb->postmeta} ON {$wpdb->posts}.ID = {$wpdb->postmeta}.post_id"; // Role Scoper modification: was LEFT JOIN in WP 3.0 core (TODO: would that botch uro join results? // meta_key and meta_value might be slashed $meta_key = stripslashes($meta_key); $meta_value = stripslashes($meta_value); if (!empty($meta_key)) { $where .= $wpdb->prepare(" AND {$wpdb->postmeta}.meta_key = %s", $meta_key); } if (!empty($meta_value)) { $where .= $wpdb->prepare(" AND {$wpdb->postmeta}.meta_value = %s", $meta_value); } } if ($parent >= 0) { $where .= $wpdb->prepare(' AND post_parent = %d ', $parent); } // === BEGIN Role Scoper MODIFICATION: // allow pages of multiple statuses to be displayed (requires default status=publish to be ignored) // $where_post_type = $wpdb->prepare("post_type = '%s'", $post_type); $where_status = ''; $is_front = $scoper->is_front(); $is_teaser_active = $scoper->is_front() && scoper_get_otype_option('do_teaser', 'post') && scoper_get_otype_option('use_teaser', 'post', $post_type); $private_teaser = $is_teaser_active && scoper_get_otype_option('use_teaser', 'post', $post_type) && !scoper_get_otype_option('teaser_hide_private', 'post', $post_type); if ($is_front && (!empty($current_rs_user->ID) || $private_teaser)) { $frontend_list_private = scoper_get_otype_option('private_items_listable', 'post', 'page'); } else { $frontend_list_private = false; } // WP core does not include private pages in query. Include private statuses in anticipation of user-specific filtering if ($post_status && ('publish' != $post_status || $is_front && !$frontend_list_private)) { $where_status = $wpdb->prepare("post_status = '%s'", $post_status); } else { // since we will be applying status clauses based on content-specific roles and restrictions, only a sanity check safeguard is needed when post_status is unspecified or defaulted to "publish" $safeguard_statuses = array(); foreach (get_post_stati(array('internal' => false), 'object') as $status_name => $status_obj) { if (!$is_front || $status_obj->private || $status_obj->public) { $safeguard_statuses[] = $status_name; } } $where_status = "post_status IN ('" . implode("','", $safeguard_statuses) . "')"; } $query = "SELECT {$fields} FROM {$wpdb->posts} {$join} WHERE 1=1 AND {$where_post_type} AND ( {$where_status} {$where} {$author_query} ) ORDER BY {$sort_column} {$sort_order}"; if (!empty($number)) { $query .= ' LIMIT ' . $offset . ',' . $number; } if ($is_teaser_active && !defined('SCOPER_TEASER_HIDE_PAGE_LISTING')) { // We are in the front end and the teaser is enabled for pages $query = apply_filters('objects_request_rs', $query, 'post', $post_type, array('force_teaser' => true)); $pages = scoper_get_results($query); // execute unfiltered query // Pass results of unfiltered query through the teaser filter. // If listing private pages is disabled, they will be omitted completely, but restricted published pages // will still be teased. This is a slight design compromise to satisfy potentially conflicting user goals without yet another option $pages = apply_filters('objects_results_rs', $pages, 'post', (array) $post_type, array('request' => $query, 'force_teaser' => true, 'object_type' => $post_type)); // restore buffered titles in case they were filtered previously scoper_restore_property_array($pages, $titles, 'ID', 'post_title'); $pages = apply_filters('objects_teaser_rs', $pages, 'post', $post_type, array('request' => $query, 'force_teaser' => true)); if ($frontend_list_private) { if (!scoper_get_otype_option('teaser_hide_private', 'post', $post_type)) { $tease_all = true; } } } else { $_args = array('skip_teaser' => true); if (in_array($GLOBALS['pagenow'], array('post.php', 'post-new.php'))) { if ($post_type_obj = get_post_type_object($post_type)) { $plural_name = plural_name_from_cap_rs($post_type_obj); $_args['alternate_reqd_caps'][0] = array("create_child_{$plural_name}"); } } // Pass query through the request filter $query = apply_filters('objects_request_rs', $query, 'post', $post_type, $_args); // Execute the filtered query $pages = scoper_get_results($query); // restore buffered titles in case they were filtered previously scoper_restore_property_array($pages, $titles, 'ID', 'post_title'); } if (empty($pages)) { // alternate hook name (WP core already applied get_pages filter) return apply_filters('get_pages_rs', array(), $r); } // // === END Role Scoper MODIFICATION === // ==================================== // Role Scoper note: WP core get_pages has already updated wp_cache and pagecache with unfiltered results. update_page_cache($pages); // === BEGIN Role Scoper MODIFICATION: Support a disjointed pages tree with some parents hidden ======== if ($child_of || empty($tease_all)) { // if we're including all pages with teaser, no need to continue thru tree remapping $ancestors = ScoperAncestry::get_page_ancestors(); // array of all ancestor IDs for keyed page_id, with direct parent first $orderby = $sort_column; if ($parent > 0 || !$hierarchical) { $remap_parents = false; } else { // if these settings were passed into this get_pages call, use them if (-1 === $remap_parents) { $remap_parents = scoper_get_option('remap_page_parents'); } if ($remap_parents) { if (-1 === $enforce_actual_depth) { $enforce_actual_depth = scoper_get_option('enforce_actual_page_depth'); } if (-1 === $remap_thru_excluded_parent) { $remap_thru_excluded_parent = scoper_get_option('remap_thru_excluded_page_parent'); } } } $remap_args = compact('child_of', 'parent', 'exclude', 'depth', 'orderby', 'remap_parents', 'enforce_actual_depth', 'remap_thru_excluded_parent'); // one or more of these args may have been modified after extraction ScoperHardway::remap_tree($pages, $ancestors, 'ID', 'post_parent', $remap_args); } // === END Role Scoper MODIFICATION === // ==================================== if (!empty($exclude_tree)) { $exclude = array(); $exclude = (int) $exclude_tree; $children = get_page_children($exclude, $pages); // RS note: okay to use unfiltered function here since it's only used for excluding $excludes = array(); foreach ($children as $child) { $excludes[] = $child->ID; } $excludes[] = $exclude; $total = count($pages); for ($i = 0; $i < $total; $i++) { if (in_array($pages[$i]->ID, $excludes)) { unset($pages[$i]); } } } if (!empty($append_page) && !empty($pages)) { $found = false; foreach (array_keys($pages) as $key) { if ($post->post_parent == $pages[$key]->ID) { $found = true; break; } } if (empty($found)) { $pages[] = $append_page; } } // re-index the array, just in case anyone cares $pages = array_values($pages); // === BEGIN Role Scoper MODIFICATION: cache key and flag specific to access type and user/groups // if (!$no_cache) { $cache[$ckey] = $pages; $current_rs_user->cache_set($cache, $cache_flag); } // alternate hook name (WP core already applied get_pages filter) $pages = apply_filters('get_pages_rs', $pages, $r); // // === END Role Scoper MODIFICATION === // ==================================== return $pages; }
function callback($path = '', $blog_id = 0) { $blog_id = $this->api->switch_to_blog_and_validate_user($this->api->get_blog_id($blog_id)); if (is_wp_error($blog_id)) { return $blog_id; } $args = $this->query_args(); if ($args['number'] < 1) { $args['number'] = 20; } elseif (100 < $args['number']) { return new WP_Error('invalid_number', 'The NUMBER parameter must be less than or equal to 100.', 400); } if (isset($args['type']) && !$this->is_post_type_allowed($args['type'])) { return new WP_Error('unknown_post_type', 'Unknown post type', 404); } // Normalize post_type if (isset($args['type']) && 'any' == $args['type']) { if (version_compare($this->api->version, '1.1', '<')) { $args['type'] = array('post', 'page'); } else { // 1.1+ $args['type'] = $this->_get_whitelisted_post_types(); } } $query = array('posts_per_page' => $args['number'], 'order' => $args['order'], 'orderby' => $args['order_by'], 'post_type' => isset($args['type']) ? $args['type'] : null, 'post_status' => $args['status'], 'post_parent' => isset($args['parent_id']) ? $args['parent_id'] : null, 'author' => isset($args['author']) && 0 < $args['author'] ? $args['author'] : null, 's' => isset($args['search']) ? $args['search'] : null); if (isset($args['meta_key'])) { $show = false; if ($this->is_metadata_public($args['meta_key'])) { $show = true; } if (current_user_can('edit_post_meta', $query['post_type'], $args['meta_key'])) { $show = true; } if (is_protected_meta($args['meta_key'], 'post') && !$show) { return new WP_Error('invalid_meta_key', 'Invalid meta key', 404); } $meta = array('key' => $args['meta_key']); if (isset($args['meta_value'])) { $meta['value'] = $args['meta_value']; } $query['meta_query'] = array($meta); } if (isset($args['sticky']) && ($sticky = get_option('sticky_posts')) && is_array($sticky)) { if ($args['sticky']) { $query['post__in'] = $sticky; } else { $query['post__not_in'] = $sticky; $query['ignore_sticky_posts'] = 1; } } else { $query['post__not_in'] = $sticky; $query['ignore_sticky_posts'] = 1; } if (isset($args['exclude'])) { $query['post__not_in'] = array_merge($query['post__not_in'], (array) $args['exclude']); } if (isset($args['category'])) { $category = get_term_by('slug', $args['category'], 'category'); if ($category === false) { $query['category_name'] = $args['category']; } else { $query['cat'] = $category->term_id; } } if (isset($args['tag'])) { $query['tag'] = $args['tag']; } if (isset($args['page'])) { if ($args['page'] < 1) { $args['page'] = 1; } $query['paged'] = $args['page']; } else { if ($args['offset'] < 0) { $args['offset'] = 0; } $query['offset'] = $args['offset']; } if (isset($args['before'])) { $this->date_range['before'] = $args['before']; } if (isset($args['after'])) { $this->date_range['after'] = $args['after']; } if ($this->date_range) { add_filter('posts_where', array($this, 'handle_date_range')); } /** * 'column' necessary for the me/posts endpoint (which extends sites/$site/posts). * Would need to be added to the sites/$site/posts definition if we ever want to * use it there. */ $column_whitelist = array('post_modified_gmt'); if (isset($args['column']) && in_array($args['column'], $column_whitelist)) { $query['column'] = $args['column']; } $wp_query = new WP_Query($query); if ($this->date_range) { remove_filter('posts_where', array($this, 'handle_date_range')); $this->date_range = array(); } $return = array(); $excluded_count = 0; foreach (array_keys($this->response_format) as $key) { switch ($key) { case 'found': $return[$key] = (int) $wp_query->found_posts; break; case 'posts': if (isset($args['exclude_tree']) && is_post_type_hierarchical($args['type'])) { // get_page_children is a misnomer; it supports all hierarchical post types $post_descendants = get_page_children($args['exclude_tree'], $wp_query->posts); $exclude_tree = array($args['exclude_tree']); foreach ($post_descendants as $child) { $exclude_tree[] = $child->ID; } } $posts = array(); foreach ($wp_query->posts as $post) { $the_post = $this->get_post_by('ID', $post->ID, $args['context']); $is_excluded_from_tree = isset($exclude_tree) && in_array($post->ID, $exclude_tree); if ($the_post && !is_wp_error($the_post) && !$is_excluded_from_tree) { $posts[] = $the_post; } else { $excluded_count++; } } if ($posts) { do_action('wpcom_json_api_objects', 'posts', count($posts)); } $return[$key] = $posts; break; } } $return['found'] -= $excluded_count; return $return; }
<li class="nxs-placeholder nxs-containshovermenu1 nxs-runtime-autocellsize nxs-one-third nxs-unistyle-footer nxs-unistyled nxs-not-unicontented nxs-widgettype-blog nxs-column-2-3" style=""> <div class="ABC nxs-height100 "> <div class="XYZ"> <div class="nxs-placeholder-content-wrap nxs-crop "> <div id="nxs-widget-b1021349230" class="nxs-widget nxs-widget-b1021349230 nxs-blog "> <div class="nxs-blog-minimal nxs-blogentries nxs-paging-page-0 default"> <h2 class="nxs-title nxs-align-left"><?php _e('Our Services'); ?> </h2> <div class="nxs-clear nxs-filler"></div> <?php $page_data = get_page_by_title('Services We Offer'); $my_wp_query = new WP_Query(); $all_wp_pages = $my_wp_query->query(array('post_type' => 'page', 'posts_per_page' => -1)); $list_child = get_page_children($page_data->ID, $all_wp_pages); ?> <ul> <?php foreach ($list_child as $key => $value) { ?> <li class="nxs-applylinkvarcolor nxs-default-p nxs-padding-bottom0 nxs-padding-left20"> <span class="nxs-icon-arrow-right2 font-icon"></span> <a href="<?php echo $value->guid; ?> "><span><?php echo $value->post_title; ?> </span></a> </li>
public static function PrintFooterMenu() { $page_data = get_pages(); if (is_object(self::$operational_data[1]['MenuLinksModule'])) { $footer_links = self::$operational_data[1]['MenuLinksModule']->features['MenuLinksFeature']->GetExludedFooterPages(); } if (!empty($footer_links)) { $include_string = ''; foreach ($footer_links as $link_id) { $include_string .= $link_id . ','; $children = get_page_children($link_id, $page_data); foreach ($children as $child) { $include_string .= $child->ID . ','; } } wp_list_pages(array('exclude' => $include_string, 'depth' => 1, 'title_li' => 0)); } else { wp_list_pages(array('depth' => 1, 'title_li' => 0)); } }
/** * Retrieve a list of pages. * * The defaults that can be overridden are the following: 'child_of', * 'sort_order', 'sort_column', 'post_title', 'hierarchical', 'exclude', * 'include', 'meta_key', 'meta_value','authors', 'number', and 'offset'. * * @since 1.5.0 * @uses $wpdb * * @param mixed $args Optional. Array or string of options that overrides defaults. * @return array List of pages matching defaults or $args */ function &get_pages($args = '') { global $wpdb; $defaults = array('child_of' => 0, 'sort_order' => 'ASC', 'sort_column' => 'post_title', 'hierarchical' => 1, 'exclude' => array(), 'include' => array(), 'meta_key' => '', 'meta_value' => '', 'authors' => '', 'parent' => -1, 'exclude_tree' => '', 'number' => '', 'offset' => 0, 'post_type' => 'page', 'post_status' => 'publish'); $r = wp_parse_args($args, $defaults); extract($r, EXTR_SKIP); $number = (int) $number; $offset = (int) $offset; // Make sure the post type is hierarchical $hierarchical_post_types = get_post_types(array('hierarchical' => true)); if (!in_array($post_type, $hierarchical_post_types)) { return false; } // Make sure we have a valid post status if (!in_array($post_status, get_post_stati())) { return false; } $cache = array(); $key = md5(serialize(compact(array_keys($defaults)))); if ($cache = wp_cache_get('get_pages', 'posts')) { if (is_array($cache) && isset($cache[$key])) { $pages = apply_filters('get_pages', $cache[$key], $r); return $pages; } } if (!is_array($cache)) { $cache = array(); } $inclusions = ''; if (!empty($include)) { $child_of = 0; //ignore child_of, parent, exclude, meta_key, and meta_value params if using include $parent = -1; $exclude = ''; $meta_key = ''; $meta_value = ''; $hierarchical = false; $incpages = wp_parse_id_list($include); if (!empty($incpages)) { foreach ($incpages as $incpage) { if (empty($inclusions)) { $inclusions = $wpdb->prepare(' AND ( ID = %d ', $incpage); } else { $inclusions .= $wpdb->prepare(' OR ID = %d ', $incpage); } } } } if (!empty($inclusions)) { $inclusions .= ')'; } $exclusions = ''; if (!empty($exclude)) { $expages = wp_parse_id_list($exclude); if (!empty($expages)) { foreach ($expages as $expage) { if (empty($exclusions)) { $exclusions = $wpdb->prepare(' AND ( ID <> %d ', $expage); } else { $exclusions .= $wpdb->prepare(' AND ID <> %d ', $expage); } } } } if (!empty($exclusions)) { $exclusions .= ')'; } $author_query = ''; if (!empty($authors)) { $post_authors = preg_split('/[\\s,]+/', $authors); if (!empty($post_authors)) { foreach ($post_authors as $post_author) { //Do we have an author id or an author login? if (0 == intval($post_author)) { $post_author = get_userdatabylogin($post_author); if (empty($post_author)) { continue; } if (empty($post_author->ID)) { continue; } $post_author = $post_author->ID; } if ('' == $author_query) { $author_query = $wpdb->prepare(' post_author = %d ', $post_author); } else { $author_query .= $wpdb->prepare(' OR post_author = %d ', $post_author); } } if ('' != $author_query) { $author_query = " AND ({$author_query})"; } } } $join = ''; $where = "{$exclusions} {$inclusions} "; if (!empty($meta_key) || !empty($meta_value)) { $join = " LEFT JOIN {$wpdb->postmeta} ON ( {$wpdb->posts}.ID = {$wpdb->postmeta}.post_id )"; // meta_key and meta_value might be slashed $meta_key = stripslashes($meta_key); $meta_value = stripslashes($meta_value); if (!empty($meta_key)) { $where .= $wpdb->prepare(" AND {$wpdb->postmeta}.meta_key = %s", $meta_key); } if (!empty($meta_value)) { $where .= $wpdb->prepare(" AND {$wpdb->postmeta}.meta_value = %s", $meta_value); } } if ($parent >= 0) { $where .= $wpdb->prepare(' AND post_parent = %d ', $parent); } $where_post_type = $wpdb->prepare("post_type = '%s' AND post_status = '%s'", $post_type, $post_status); $query = "SELECT * FROM {$wpdb->posts} {$join} WHERE ({$where_post_type}) {$where} "; $query .= $author_query; $query .= " ORDER BY " . $sort_column . " " . $sort_order; if (!empty($number)) { $query .= ' LIMIT ' . $offset . ',' . $number; } $pages = $wpdb->get_results($query); if (empty($pages)) { $pages = apply_filters('get_pages', array(), $r); return $pages; } // Sanitize before caching so it'll only get done once $num_pages = count($pages); for ($i = 0; $i < $num_pages; $i++) { $pages[$i] = sanitize_post($pages[$i], 'raw'); } // Update cache. update_page_cache($pages); if ($child_of || $hierarchical) { $pages =& get_page_children($child_of, $pages); } if (!empty($exclude_tree)) { $exclude = (int) $exclude_tree; $children = get_page_children($exclude, $pages); $excludes = array(); foreach ($children as $child) { $excludes[] = $child->ID; } $excludes[] = $exclude; $num_pages = count($pages); for ($i = 0; $i < $num_pages; $i++) { if (in_array($pages[$i]->ID, $excludes)) { unset($pages[$i]); } } } $cache[$key] = $pages; wp_cache_set('get_pages', $cache, 'posts'); $pages = apply_filters('get_pages', $pages, $r); return $pages; }
function &get_pages($args = '') { global $wpdb; parse_str($args, $r); if (!isset($r['child_of'])) { $r['child_of'] = 0; } if (!isset($r['sort_column'])) { $r['sort_column'] = 'post_title'; } if (!isset($r['sort_order'])) { $r['sort_order'] = 'ASC'; } $exclusions = ''; if (!empty($r['exclude'])) { $expages = preg_split('/[\\s,]+/', $r['exclude']); if (count($expages)) { foreach ($expages as $expage) { $exclusions .= ' AND ID <> ' . intval($expage) . ' '; } } } $pages = $wpdb->get_results("SELECT * " . "FROM {$wpdb->posts} " . "WHERE post_status = 'static' " . "{$exclusions} " . "ORDER BY " . $r['sort_column'] . " " . $r['sort_order']); if (empty($pages)) { return array(); } // Update cache. update_page_cache($pages); if ($r['child_of']) { $pages =& get_page_children($r['child_of'], $pages); } return $pages; }