本文整理汇总了PHP中BYT_Theme_Utils::get_post_descendants方法的典型用法代码示例。如果您正苦于以下问题:PHP BYT_Theme_Utils::get_post_descendants方法的具体用法?PHP BYT_Theme_Utils::get_post_descendants怎么用?PHP BYT_Theme_Utils::get_post_descendants使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BYT_Theme_Utils
的用法示例。
在下文中一共展示了BYT_Theme_Utils::get_post_descendants方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: list_locations
function list_locations($location_id = 0, $paged = 0, $per_page = -1, $orderby = '', $order = '', $featured_only = false)
{
$location_ids = array();
if ($location_id > 0) {
$location_ids[] = $location_id;
$location_descendants = BYT_Theme_Utils::get_post_descendants($location_id, 'location');
foreach ($location_descendants as $location) {
$location_ids[] = $location->ID;
}
}
$args = array('post_type' => 'location', 'post_status' => array('publish'), 'posts_per_page' => $per_page, 'paged' => $paged, 'orderby' => $orderby, 'suppress_filters' => false, 'order' => $order, 'meta_query' => array('relation' => 'AND'));
if (count($location_ids) > 0) {
$args['meta_query'][] = array('key' => 'location_location_post_id', 'value' => $location_ids, 'compare' => 'IN');
}
if (isset($featured_only) && $featured_only) {
$args['meta_query'][] = array('key' => 'location_is_featured', 'value' => 1, 'compare' => '=', 'type' => 'numeric');
}
$posts_query = new WP_Query($args);
$locations = array();
if ($posts_query->have_posts()) {
while ($posts_query->have_posts()) {
global $post;
$posts_query->the_post();
$locations[] = $post;
}
}
$results = array('total' => $posts_query->found_posts, 'results' => $locations);
wp_reset_postdata();
return $results;
}
示例2: list_car_rentals
function list_car_rentals($paged = 0, $per_page = -1, $orderby = '', $order = '', $location_id = 0, $car_types_array = array(), $car_rental_tags_array = array(), $search_args = array(), $featured_only = false, $author_id = null, $include_private = false, $count_only = false)
{
global $byt_theme_globals;
$location_ids = array();
if ($location_id > 0) {
$location_ids[] = $location_id;
$location_descendants = BYT_Theme_Utils::get_post_descendants($location_id, 'location');
foreach ($location_descendants as $location) {
$location_ids[] = $location->ID;
}
}
if (isset($search_args['keyword']) && strlen($search_args['keyword']) > 0) {
$args = array('s' => $search_args['keyword'], 'post_type' => 'location', 'posts_per_page' => -1, 'post_status' => 'publish', 'suppress_filters' => false);
$location_posts = get_posts($args);
foreach ($location_posts as $location) {
$location_ids[] = $location->ID;
}
$descendant_location_ids = array();
foreach ($location_ids as $temp_location_id) {
$location_descendants = BYT_Theme_Utils::get_post_descendants($temp_location_id, 'location');
foreach ($location_descendants as $location) {
$descendant_location_ids[] = $location->ID;
}
}
$location_ids = array_merge($descendant_location_ids, $location_ids);
}
$args = array('post_type' => 'car_rental', 'post_status' => array('publish'), 'posts_per_page' => $per_page, 'paged' => $paged, 'orderby' => $orderby, 'suppress_filters' => false, 'order' => $order, 'meta_query' => array('relation' => 'AND'));
if ($orderby == 'price') {
$args['meta_key'] = 'car_rental_price_per_day';
$args['orderby'] = 'meta_value_num';
}
if (isset($search_args['keyword']) && strlen($search_args['keyword']) > 0) {
$args['s'] = $search_args['keyword'];
}
if ($include_private) {
$args['post_status'][] = 'private';
}
if (isset($featured_only) && $featured_only) {
$args['meta_query'][] = array('key' => 'car_rental_is_featured', 'value' => 1, 'compare' => '=', 'type' => 'numeric');
}
if (isset($author_id)) {
$author_id = intval($author_id);
if ($author_id > 0) {
$args['author'] = $author_id;
}
}
if (count($location_ids) > 0) {
$args['meta_query'][] = array('key' => 'car_rental_location_post_id', 'value' => $location_ids, 'compare' => 'IN');
$args['byt_location_ids'] = $location_ids;
}
if (!empty($car_types_array)) {
$args['tax_query'][] = array('taxonomy' => 'car_type', 'field' => 'id', 'terms' => $car_types_array, 'operator' => 'IN');
}
if (!empty($car_rental_tags_array)) {
$args['tax_query'][] = array('taxonomy' => 'car_rental_tag', 'field' => 'id', 'terms' => $car_rental_tags_array, 'operator' => 'IN');
}
$search_only_available = false;
if (isset($search_args['search_only_available'])) {
$search_only_available = $search_args['search_only_available'];
}
if (isset($search_args['prices'])) {
$args['prices'] = $search_args['prices'];
$args['price_range_bottom'] = $byt_theme_globals->get_price_range_bottom();
$args['price_range_increment'] = $byt_theme_globals->get_price_range_increment();
$args['price_range_count'] = $byt_theme_globals->get_price_range_count();
}
if (isset($search_args['date_from'])) {
$args['byt_date_from'] = $search_args['date_from'];
}
if (isset($search_args['date_to'])) {
$args['byt_date_to'] = $search_args['date_to'];
}
$args['search_only_available'] = $search_only_available;
add_filter('posts_where', array($this, 'car_rentals_search_where'), 10, 2);
add_filter('posts_fields', array($this, 'car_rentals_search_fields'), 10, 2);
add_filter('posts_groupby', array($this, 'car_rentals_search_groupby'), 10, 2);
add_filter('posts_join', array($this, 'car_rentals_search_join'), 10, 2);
$posts_query = new WP_Query($args);
// echo $posts_query->request;
if ($count_only) {
$results = array('total' => $posts_query->found_posts, 'results' => null);
} else {
$results = array();
if ($posts_query->have_posts()) {
while ($posts_query->have_posts()) {
global $post;
$posts_query->the_post();
$results[] = $post;
}
}
$results = array('total' => $posts_query->found_posts, 'results' => $results);
}
wp_reset_postdata();
remove_filter('posts_where', array($this, 'car_rentals_search_where'));
remove_filter('posts_fields', array($this, 'car_rentals_search_fields'));
remove_filter('posts_groupby', array($this, 'car_rentals_search_groupby'));
remove_filter('posts_join', array($this, 'car_rentals_search_join'));
return $results;
}
示例3: get_post_descendants
public static function get_post_descendants($parent_id, $post_type)
{
$children = array();
$posts = get_posts(array('numberposts' => -1, 'post_status' => 'publish', 'post_type' => $post_type, 'post_parent' => $parent_id, 'suppress_filters' => false));
foreach ($posts as $child) {
$gchildren = BYT_Theme_Utils::get_post_descendants($child->ID, $post_type);
if (!empty($gchildren)) {
$children = array_merge($children, $gchildren);
}
}
$children = array_merge($children, $posts);
return $children;
}