本文整理汇总了PHP中get_page_children函数的典型用法代码示例。如果您正苦于以下问题:PHP get_page_children函数的具体用法?PHP get_page_children怎么用?PHP get_page_children使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get_page_children函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。
示例1: get_subpages
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);
}
开发者ID:gmateu,项目名称:liceuWP,代码行数:7,代码来源:header.php
示例2: widget
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>";
}
开发者ID:openterengganu,项目名称:govintranet,代码行数:54,代码来源:ht_about_this_page_ajax.php
示例3: wanderoper_permalink
/**
* 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>';
}
开发者ID:TJgxB5ZeKaPttEso,项目名称:wanderoper-2015,代码行数:15,代码来源:extras.php
示例4: getPageChildren
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;
}
}
开发者ID:laiello,项目名称:cootheme2,代码行数:14,代码来源:PageModel.php
示例5: setup
//.........这里部分代码省略.........
}
$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;
}
}
开发者ID:alterfw,项目名称:hero,代码行数:101,代码来源:Model.php
示例6: WP_Query
<?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;
开发者ID:TeamSubjectMatter,项目名称:juddfoundation,代码行数:31,代码来源:content-two-column.php
示例7: fr_get_sitemap
/**
* 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
}
开发者ID:sdellow,项目名称:wp-framework,代码行数:69,代码来源:functions.php
示例8: acf_get_grouped_posts
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;
}
开发者ID:sdh100shaun,项目名称:pantheon,代码行数:71,代码来源:api-helpers.php
示例9: get_pages
//.........这里部分代码省略.........
$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);
}
开发者ID:SayenkoDesign,项目名称:ividf,代码行数:101,代码来源:post.php
示例10: ajax_render_rules
/**
* 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":
//.........这里部分代码省略.........
开发者ID:radikalportal,项目名称:radikalportal,代码行数:101,代码来源:class-spu-helper.php
示例11: getImages
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;
}
}
开发者ID:ryandong82,项目名称:colorfulladysite,代码行数:76,代码来源:rbs_gallery_source.php
示例12: get_pages
//.........这里部分代码省略.........
}
$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;
}
开发者ID:rmccue,项目名称:wordpress-unit-tests,代码行数:101,代码来源:post.php
示例13: ajax_render_location
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;
//.........这里部分代码省略.........
开发者ID:bsfignoni,项目名称:revistafilm,代码行数:101,代码来源:field_group.php
示例14: mf_inner_location_box
/**
* 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>';
}
开发者ID:hansstam,项目名称:makerfaire,代码行数:78,代码来源:location.php
示例15: scoper_get_page_descendant_ids
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;
}
开发者ID:btj,项目名称:cscircles-wp-content,代码行数:19,代码来源:filters-admin-save_rs.php
|
请发表评论