本文整理汇总了PHP中WP_Query::query方法的典型用法代码示例。如果您正苦于以下问题:PHP WP_Query::query方法的具体用法?PHP WP_Query::query怎么用?PHP WP_Query::query使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类WP_Query
的用法示例。
在下文中一共展示了WP_Query::query方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: widget
function widget($args, $instance)
{
extract($args, EXTR_SKIP);
echo $before_widget . $before_title;
echo ec3_widget_title($instance['title'], 'Upcoming Events');
echo $after_title;
if (ec3_check_installed(__('Upcoming Events', 'ec3'))) {
// Parse $limit:
// NUMBER - limits number of posts
// NUMBER days - next NUMBER of days
$limit = $instance['limit'];
$num = intval($limit);
$query = new WP_Query();
if (preg_match('/^ *([0-9]+) *d(ays?)?/', $limit, $matches)) {
$query->query('ec3_days=' . intval($matches[1]));
} elseif ($num > 0) {
$query->query('ec3_after=today&posts_per_page=' . $num);
} elseif ($num < 0) {
$query->query('ec3_before=today&order=asc&posts_per_page=' . abs($num));
} else {
$query->query('ec3_after=today&posts_per_page=5');
}
echo "<ul class='ec3_events'>";
echo '<!-- Generated by Event-Calendar v' . ec3_get_version() . ' -->' . "\n";
if ($query->have_posts()) {
$current_date = false;
for ($evt = ec3_iter_all_events_q($query); $evt->valid(); $evt->next()) {
// Date changed?
$date = ec3_get_date();
if (!$current_date || $current_date != $date) {
if ($current_date) {
echo "</ul></li>\n";
}
echo "<li class='ec3_list ec3_list_day'>{$date}:\n<ul>\n";
$current_date = $date;
}
// Print the event.
echo ' <li><a href="' . get_permalink() . '">' . get_the_title() . ' (' . ec3_get_start_time() . ')</a></li>' . "\n";
}
if ($current_date) {
echo "</ul></li>\n";
}
} else {
echo "<li>" . __('No events.', 'ec3') . "</li>\n";
}
echo "</ul>\n";
}
echo $after_widget;
}
示例2: dpa_get_progress
/**
* Retrieves a list of progress posts matching criteria
*
* If you try to use this function, you will need to implement your own switch_to_blog and wp_reset_postdata() handling if running in a multisite
* and in a dpa_is_running_networkwide() configuration, otherwise the data won't be fetched from the appropriate site.
*
* @param array|string $args All the arguments supported by {@link WP_Query}, and some more.
* @return array Posts
* @since Achievements (3.0)
*/
function dpa_get_progress($args = array())
{
$defaults = array('no_found_rows' => true, 'order' => 'DESC', 'orderby' => 'date', 'post_type' => dpa_get_progress_post_type(), 'posts_per_page' => -1, 'post_status' => array(dpa_get_locked_status_id(), dpa_get_unlocked_status_id()));
$args = dpa_parse_args($args, $defaults, 'get_progress');
$progress = new WP_Query();
return apply_filters('dpa_get_progress', $progress->query($args), $args);
}
示例3: array
/**
*
*
*
*
* @since 1.0.9
* */
function _top_ajax_search()
{
if (STInput::request('action') != 'st_top_ajax_search') {
return;
}
//Small security
check_ajax_referer('st_search_security', 'security');
$s = STInput::get('s');
$arg = array('post_type' => array('post', 'st_hotel', 'st_rental', 'location', 'st_tours', 'st_holidays', 'st_cars', 'st_activity'), 'posts_per_page' => 10, 's' => $s, 'suppress_filters' => false);
$query = new WP_Query();
$query->is_admin = false;
$query->query($arg);
$r = array();
while ($query->have_posts()) {
$query->the_post();
$post_type = get_post_type(get_the_ID());
$obj = get_post_type_object($post_type);
$item = array('title' => get_the_title(), 'id' => get_the_ID(), 'type' => $obj->labels->singular_name, 'url' => get_permalink(), 'obj' => $obj);
if ($post_type == 'location') {
$item['url'] = home_url(esc_url_raw('?s=&post_type=st_hotel&location_id=' . get_the_ID()));
}
$r['data'][] = $item;
}
wp_reset_query();
echo json_encode($r);
die;
}
示例4: 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);
}
示例5: recentPosts
function recentPosts()
{
$rPosts = new WP_Query();
$rPosts->query('showposts=4');
while ($rPosts->have_posts()) {
$rPosts->the_post();
?>
<div class="col-md-3 prj-item col-sm-6">
<a href="<?php
the_permalink();
?>
">
<?php
the_post_thumbnail('recent-thumbnails');
?>
<div class="info">
<i class="fa fa-plus"></i>
<h5><?php
the_title();
?>
</h5>
<!--<h6> cats </h6> -->
</div>
</a>
</div>
<?php
}
wp_reset_query();
}
示例6: myLoop
function myLoop($atts, $content = null)
{
extract(shortcode_atts(array("pagination" => 'true', "query" => '', "category" => ''), $atts));
global $wp_query, $paged, $post;
$temp = $wp_query;
$wp_query = null;
$wp_query = new WP_Query();
$query .= 'post_type=person';
$wp_query->query($query);
ob_start();
?>
<?php
while ($wp_query->have_posts()) {
$wp_query->the_post();
?>
<?php
get_template_part('content', get_post_type());
?>
<?php
}
?>
<?php
$wp_query = null;
$wp_query = $temp;
$content = ob_get_contents();
ob_end_clean();
return $content;
}
示例7: addPopupByURL
protected function addPopupByURL($matches)
{
global $wp_query;
$pageId = $matches[1];
if (is_numeric($pageId)) {
$post = get_post($pageId);
} else {
$query = new WP_Query();
//simulate category query in order to fool ACE
$temp = $wp_query->is_category;
$wp_query->is_category = true;
$posts = $query->query(array('name' => $pageId));
$wp_query->is_category = $temp;
if (empty($posts)) {
return "#error-popup-{$pageId}";
}
$post = $posts[0];
}
if (!$post) {
return "#error-popup-{$pageId}";
}
$this->replaceHappened = true;
$this->content[$post->ID] = '<div class="popup-content">' . apply_filters('the_content', $post->post_content) . '</div>';
return '#popup" onclick="return showPopup(\'' . $post->ID . '\')';
}
示例8: wp_link_query
/**
* Performs post queries for internal linking.
*
* @since 3.1.0
*
* @param array $args Optional. Accepts 'pagenum' and 's' (search) arguments.
* @return array Results.
*/
function wp_link_query($args = array())
{
$pts = get_post_types(array('publicly_queryable' => true), 'objects');
$pt_names = array_keys($pts);
$query = array('post_type' => $pt_names, 'suppress_filters' => true, 'update_post_term_cache' => false, 'update_post_meta_cache' => false, 'post_status' => 'publish', 'order' => 'DESC', 'orderby' => 'post_date', 'posts_per_page' => 20);
$args['pagenum'] = isset($args['pagenum']) ? absint($args['pagenum']) : 1;
if (isset($args['s'])) {
$query['s'] = $args['s'];
}
$query['offset'] = $args['pagenum'] > 1 ? $query['posts_per_page'] * ($args['pagenum'] - 1) : 0;
// Do main query.
$get_posts = new WP_Query();
$posts = $get_posts->query($query);
// Check if any posts were found.
if (!$get_posts->post_count) {
return false;
}
// Build results.
$results = array();
foreach ($posts as $post) {
if ('post' == $post->post_type) {
$info = mysql2date(__('Y/m/d'), $post->post_date);
} else {
$info = $pts[$post->post_type]->labels->singular_name;
}
$results[] = array('ID' => $post->ID, 'title' => trim(esc_html(strip_tags(get_the_title($post)))), 'permalink' => get_permalink($post->ID), 'info' => $info);
}
return $results;
}
示例9: get_items
/**
* Get a collection of posts.
*
* @param WP_REST_Request $request Full details about the request.
* @return WP_Error|WP_REST_Response
*/
public function get_items($request)
{
$args = array();
$args['author'] = $request['author'];
$args['paged'] = $request['page'];
$args['posts_per_page'] = $request['per_page'];
$args['post_parent'] = $request['parent'];
$args['post_status'] = $request['status'];
$args['s'] = $request['search'];
if (is_array($request['filter'])) {
$args = array_merge($args, $request['filter']);
unset($args['filter']);
}
// Force the post_type argument, since it's not a user input variable.
$args['post_type'] = $this->post_type;
/**
* Filter the query arguments for a request.
*
* Enables adding extra arguments or setting defaults for a post
* collection request.
*
* @param array $args Key value array of query var to query value.
* @param WP_REST_Request $request The request used.
*/
$args = apply_filters('rest_post_query', $args, $request);
$query_args = $this->prepare_items_query($args);
$posts_query = new WP_Query();
$query_result = $posts_query->query($query_args);
$posts = array();
foreach ($query_result as $post) {
if (!$this->check_read_permission($post)) {
continue;
}
$data = $this->prepare_item_for_response($post, $request);
$posts[] = $this->prepare_response_for_collection($data);
}
$response = rest_ensure_response($posts);
$count_query = new WP_Query();
unset($query_args['paged']);
$query_result = $count_query->query($query_args);
$total_posts = $count_query->found_posts;
$response->header('X-WP-Total', (int) $total_posts);
$max_pages = ceil($total_posts / $request['per_page']);
$response->header('X-WP-TotalPages', (int) $max_pages);
$base = add_query_arg($request->get_query_params(), rest_url('/wp/v2/' . $this->get_post_type_base($this->post_type)));
if ($request['page'] > 1) {
$prev_page = $request['page'] - 1;
if ($prev_page > $max_pages) {
$prev_page = $max_pages;
}
$prev_link = add_query_arg('page', $prev_page, $base);
$response->link_header('prev', $prev_link);
}
if ($max_pages > $request['page']) {
$next_page = $request['page'] + 1;
$next_link = add_query_arg('page', $next_page, $base);
$response->link_header('next', $next_link);
}
return $response;
}
示例10: shortcode_list_posts
function shortcode_list_posts($atts, $content = null)
{
extract(shortcode_atts(array('posts_per_page' => -1, 'cat' => '', 'tag' => '', 'order' => '', 'order_by' => ''), $atts));
$args = array('post_type' => 'post', 'posts_per_page' => $posts_per_page, 'post_status' => 'publish');
if (!empty($cat)) {
$cat = split(',', str_replace(" ", "", $cat));
$args['category__and'] = $cat;
}
if (!empty($tag)) {
$tag = split(',', str_replace(" ", "", $tag));
$args['tag__in'] = $tag;
}
if ($order) {
$args['order'] = $order;
}
if ($order_by) {
$args['orderby'] = $order_by;
}
$my_query = new WP_Query();
$my_query->query($args);
$content = '<ul class="post-list" >';
while ($my_query->have_posts()) {
$my_query->the_post();
$author = get_the_author_meta('display_name');
$author_url = get_author_posts_url(get_the_author_meta('ID'));
$content .= '<li><a href="' . get_permalink() . '" title="' . get_the_title() . '">' . get_the_title() . '</a> <span>- by <a href="' . $author_url . '" title="' . $author . '">' . $author . '</a> on ' . get_the_time('F j, Y') . '</span></li>' . "\n";
}
$content .= '</ul><!-- end .post-list -->';
//wp_reset_query();
return remove_wpautop($content);
}
示例11: widget
function widget($args, $instance)
{
global $post;
extract($args, EXTR_SKIP);
echo $before_widget;
$title = empty($instance['title']) ? '' : apply_filters('widget_title', $instance['title']);
if (!empty($title)) {
echo $before_title . $title . $after_title;
}
if ((is_home() || is_front_page()) && !is_paged() && !ceo_pluginfo('disable_comic_on_home_page')) {
$chapter_on_home = '';
$chapter_on_home = get_term_by('id', ceo_pluginfo('chapter_on_home'), 'chapters');
$chapter_on_home = !is_wp_error($chapter_on_home) && !empty($chapter_on_home) ? '&chapters=' . $chapter_on_home->slug : '';
$order = ceo_pluginfo('display_first_comic_on_home_page') ? 'asc' : 'desc';
$query_args = 'post_type=comic&showposts=1&order=' . $order . $chapter_on_home;
apply_filters('ceo_display_comic_mininav_home_query', $query_args);
$comicFrontpage = new WP_Query();
$comicFrontpage->query($query_args);
while ($comicFrontpage->have_posts()) {
$comicFrontpage->the_post();
ceo_list_jump_to_comic($instance['exclude'], false);
}
} elseif (!empty($post)) {
ceo_list_jump_to_comic($instance['exclude'], false);
}
echo $after_widget;
}
示例12: array
function ut_get_posts_children_ids($parent_id)
{
/* id is empty , we leave here */
if (empty($parent_id)) {
return array();
}
$children_array = array();
$child_query = new WP_Query();
$children = $child_query->query(array('post_type' => 'page', 'order' => 'ASC', 'post_status' => 'publish', 'orderby' => 'menu_order', 'post_parent' => $parent_id));
if (!empty($children)) {
foreach ($children as $child) {
/* push current child into array */
$children_array[] = $child->ID;
/* recursive - here we go! */
$gchildren = ut_get_posts_children_ids($child->ID);
if (!empty($gchildren)) {
foreach ($gchildren as $gchild) {
$children_array[] = $gchild;
}
}
}
}
wp_reset_postdata();
return !empty($children_array) ? $children_array : array();
}
示例13: publication_query
/**
* Search for publications.
*
* @param array $args
* @return array
*/
private function publication_query($args = array())
{
$query = array('post_type' => 'seoslides-slideset', 'suppress_filters' => true, 'update_post_term_cache' => false, 'update_post_meta_cache' => false, 'post_status' => 'publish', 'order' => 'DESC', 'orderby' => 'post_date', 'posts_per_page' => 20);
$args['pagenum'] = isset($args['pagenum']) ? absint($args['pagenum']) : 1;
if (isset($args['s'])) {
$query['s'] = $args['s'];
}
$query['offset'] = $args['pagenum'] > 1 ? $query['posts_per_page'] * ($args['pagenum'] - 1) : 0;
// Run the query
$get_posts = new WP_Query();
$posts = $get_posts->query($query);
$results = array();
if (0 === $get_posts->post_count) {
return $results;
}
// Populate results
foreach ($posts as $post) {
// Get the embed ID for the first slide in the presentation
$slideset = new SEOSlides_Slideset($post->ID);
/** @var SEOSlides_Embed $embed */
$embed = SEOSlides_Module_Provider::get('SEOSlides Embed');
$embed_id = $embed->get_embed_unique_id($post->ID, $slideset->first_slide()->slug);
$embed_url = $embed->get_embed_url($post->ID, $slideset->first_slide()->slug);
$shortcode = '[seoslides embed_id="' . $embed_id . '"';
$shortcode .= ' script_src="' . preg_replace('/\\/(slides|embeds)\\//', '/embed-script/', $embed_url) . '"';
$shortcode .= ' overview_src="' . get_permalink($post) . '"';
$shortcode .= ' title="' . get_the_title($post) . '"';
$shortcode .= ' site_src="' . get_home_url() . '"';
$shortcode .= ' site_title="' . get_bloginfo('name') . '"';
$shortcode .= ' /]';
$results[] = array('ID' => $post->ID, 'title' => trim(esc_html(strip_tags(get_the_title($post)))), 'shortcode' => esc_attr($shortcode), 'info' => mysql2date(__('Y/m/d'), $post->post_date));
}
return $results;
}
示例14: choosepopup_inner_custom_box
function choosepopup_inner_custom_box()
{
// Use nonce for verification
wp_nonce_field(plugin_basename(__FILE__), 'choosepopup_noncename');
$popup_list = new WP_Query();
$popup_list->query(array('post_status' => 'publish', 'post_type' => array('post', 'page'), 'order_by' => 'menu_order, post_title', 'posts_per_page' => '-1'));
//print_r($popup_list);
if (!empty($popup_list)) {
$meta_values = get_post_meta($_GET['post'], 'popup', true);
echo '<label for="choosepopup_new_field">' . __("Popup post", 'choosepopup_textdomain') . '</label> ';
echo '<input name="choosepopup_new_field" id="choosepopup_new_field" value="' . $meta_values . '" />';
/*
echo '<option></option>';
foreach ($popup_list->posts as $q) {
if (intval($q->ID) > 0) echo '<option value="' . $q->ID . '"';
if (intval($q->ID) > 0 && intval($q->ID) == $meta_values) echo ' selected';
if (intval($q->ID) > 0) echo '>' . $q->post_title . ' '. ucfirst($q->post_type) . '</option>';
}
echo '</select>';
*/
$anc_values = get_post_meta($_GET['post'], 'anchor', true);
echo '<br /><label for="chooseanchor_new_field">Popup anchor</label> ';
echo '<input name="chooseanchor_new_field" id="chooseanchor_new_field" type="text" value="' . $anc_values . '"/>';
}
}
示例15: get_my_page_by_title
function get_my_page_by_title($title)
{
$my_wp_query = new WP_Query();
$all_wp_pages = $my_wp_query->query(array('post_type' => 'page'));
$page = get_page_by_title($title);
return $page;
}