本文整理汇总了PHP中WP_Query类的典型用法代码示例。如果您正苦于以下问题:PHP WP_Query类的具体用法?PHP WP_Query怎么用?PHP WP_Query使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了WP_Query类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: charity_vc_our_mission
function charity_vc_our_mission($atts, $content = null)
{
extract(shortcode_atts(array('our_mission' => ''), $atts));
$page_id = get_page_by_title($our_mission);
$missionQuery = new WP_Query(array("page_id" => $page_id->ID));
if ($missionQuery->have_posts()) {
$missionQuery->the_post();
$url = wp_get_attachment_image_src(get_post_thumbnail_id($page_id->ID), array(1143, 479));
?>
<!-- Save Lives Section Start Here-->
<section class="save-lives text-center parallax" style="background-image: url('<?php
echo esc_url($url[0]);
?>
')">
<div class="container">
<div class="row">
<div class="col-xs-12 col-sm-8 col-sm-offset-2 col-md-6 col-md-offset-3">
<header class="page-header">
<h2><?php
the_title();
?>
</h2>
<?php
the_content();
?>
</header>
</div>
</div>
</div>
</section>
<!-- Save Lives Section Start Here-->
<?php
}
wp_reset_postdata();
}
示例2: widget
function widget($args, $instance)
{
global $post;
extract($args, EXTR_SKIP);
echo $before_widget;
$title = empty($instance['title']) ? __('Recent Posts', 'lan-thinkupthemes') : apply_filters('widget_title', $instance['title']);
if (!empty($title)) {
echo $before_title . $title . $after_title;
}
$posts = new WP_Query('orderby=date&posts_per_page=' . $instance['postcount'] . '');
while ($posts->have_posts()) {
$posts->the_post();
// Insert post date if needed.
if ($instance['postdate'] == 'on') {
$date_input = '<a href="' . get_permalink() . '" class="date">' . get_the_date('M j, Y') . '</a>';
}
// HTML output
echo '<div class="recent-posts">';
if (has_post_thumbnail() and $instance['imageswitch'] == 'on') {
echo '<div class="image">', '<a href="' . get_permalink() . '" title="' . get_the_title() . '">' . get_the_post_thumbnail($post->ID, array(65, 65)) . '<div class="image-overlay"></div></a>', '</div>', '<div class="main">', '<a href="' . get_permalink() . '">' . get_the_title() . '</a>', $date_input, '</div>';
} else {
echo '<div class="main">', '<a href="' . get_permalink() . '">' . get_the_title() . '</a>', $date_input, '</div>';
}
echo '</div>';
}
wp_reset_query();
echo $after_widget;
}
示例3: load_user
public function load_user()
{
if ($this->id > 0) {
$current_user = get_user_by('ID', $this->id);
} elseif (function_exists('is_user_logged_in') && is_user_logged_in()) {
$current_user = wp_get_current_user();
}
if (isset($current_user) && $current_user) {
$this->id = $current_user->ID;
$this->first_name = $current_user->user_firstname;
$this->last_name = $current_user->user_lastname;
$this->email = $current_user->user_email;
$this->address = get_user_meta($current_user->ID, 'address', TRUE);
$this->is_on_mailing_list = get_user_meta($current_user->ID, 'mailing_list', TRUE);
$this->is_on_mailing_list = $this->is_on_mailing_list == 1 ? TRUE : FALSE;
$neighborhood_id = get_user_meta($current_user->ID, 'neighborhood_id', TRUE);
if (!empty($neighborhood_id) && $neighborhood_id > 0) {
$args = array('post_type' => 'wbb_neighborhood', 'post_status' => 'publish');
$query = new \WP_Query($args);
while ($query->have_posts()) {
$query->the_post();
if (get_the_ID() == $neighborhood_id) {
$this->neighborhood = new Neighborhood();
$this->neighborhood->post_id = get_the_ID();
$this->neighborhood->title = get_the_title();
break;
}
}
}
$this->get_locations();
}
}
示例4: generate_ryuzine_stylesheets
function generate_ryuzine_stylesheets()
{
// verify this came from the our screen and with proper authorization.
if (!wp_verify_nonce($_POST['ryu_regenstyles_noncename'], 'ryuzine-regenstyles_install')) {
return;
}
// Check permissions
if (!current_user_can('administrator')) {
echo "<div class='error'><p>Sorry, you do not have the correct priveledges to install the files.</p></div>";
return;
}
$my_query = null;
$my_query = new WP_Query(array('post_type' => 'ryuzine'));
if ($my_query->have_posts()) {
while ($my_query->have_posts()) {
$my_query->the_post();
$stylesheet = "";
$issuestyles = get_post_meta(get_the_ID(), '_ryustyles', false);
if (!empty($issuestyles)) {
foreach ($issuestyles as $appendstyle) {
// If there are multiple ryustyles append them //
$stylesheet = $stylesheet . $appendstyle;
}
}
if ($stylesheet != "") {
ryu_create_css($stylesheet, get_the_ID());
}
}
}
// reset css check //
// update_option('ryu_css_admin',0);
wp_reset_query();
return;
}
示例5: get_Relationships_by_Tag
public function get_Relationships_by_Tag($tag, $_method, $_route, $_path, $_headers)
{
if (empty($tag) || !is_string($tag)) {
return new WP_Error('json_options_invalid_tag', __("Invalid options tag"), ['status' => 404]);
}
$site = $_headers['REMOTE'];
$tags = explode(',', $tag);
if ($tags) {
$tags_query['relation'] = 'OR';
foreach ($tags as $tag) {
$tags_query[] = array('key' => 'related_tags', 'value' => $tag, 'compare' => 'LIKE');
}
}
$args = array('post_type' => 'relationship', 'meta_query' => array('relation' => 'AND', array('key' => 'site_address', 'value' => $site), $tags_query));
$relationships = new WP_Query($args);
if ($relationships->have_posts()) {
// Get the Target Categories
$targets = [];
while ($relationships->have_posts()) {
$relationships->the_post();
$targets[] = get_field('target_category');
}
$targets = dedupe($targets);
$related_categories = implode(', ', $targets);
// Find Matching Relationships
$args = array('post_type' => 'relationship', 'tax_query' => array(array('taxonomy' => 'related_categories', 'terms' => $related_categories)));
$relationships = new WP_Query($args);
// Build Relationships JSON Reponse
include 'related-json-response.php';
}
wp_reset_query();
return $sites;
}
示例6: bap_ajaxP_loop
function bap_ajaxP_loop($offset = '')
{
global $wp_query;
$paged = get_query_var('page') ? get_query_var('page') : 1;
$do_not_duplicate = array();
// OFFSET SETTING
if (!$offset == '' || !$offset == '0') {
$argshidepost = array('numberposts' => $offset, 'post_type' => 'post', 'post_status' => 'publish');
$hide_to_array = get_posts($argshidepost);
// HIDE OFFSETED POSTS
if ($hide_to_array) {
foreach ($hide_to_array as $post) {
$do_not_duplicate[] = $post->ID;
}
}
}
$argsmain = array('post_type' => 'post', 'post_status' => 'publish', 'paged' => $paged, 'order' => 'DESC', 'post__not_in' => $do_not_duplicate);
$wp_query = new WP_Query($argsmain);
if ($wp_query->have_posts()) {
echo '<section id="' . bap_get_option_text('bap_loopContainer') . '">';
while ($wp_query->have_posts()) {
$wp_query->the_post();
get_template_part('partials/listitem');
}
echo '</section>';
}
wp_reset_postdata();
}
示例7: parse_query
/**
* Hook into the query parsing to detect oEmbed requests.
*
* If an oEmbed request is made, trigger the output.
*
* @codeCoverageIgnore
*
* @param WP_Query $wp_query The WP_Query instance (passed by reference).
*/
public function parse_query($wp_query)
{
// Check for required params.
if (false === $wp_query->get('oembed', false)) {
return;
}
if (false === $wp_query->get('url', false)) {
status_header(400);
echo 'URL parameter missing';
exit;
}
/**
* Check for the allowed query vars and set defaults.
*
* @see WP_REST_oEmbed_Controller::register_routes()
*/
$url = esc_url_raw(get_query_var('url'));
$format = sanitize_text_field(get_query_var('format', 'json'));
/**
* Filter the maxwidth oEmbed parameter.
*
* @param int $maxwidth Maximum allowed width. Defaults to 600.
*
* @return int
*/
$maxwidth = apply_filters('oembed_default_width', 600);
$maxwidth = get_query_var('maxwidth', $maxwidth);
$callback = get_query_var('_jsonp', false);
$request = array('url' => $url, 'format' => $format, 'maxwidth' => $maxwidth, 'callback' => $callback);
echo $this->dispatch($request);
exit;
}
示例8: get_pins
public static function get_pins($args)
{
$defaults = array('numberposts' => 5, 'category' => 0, 'orderby' => 'date', 'order' => 'DESC', 'include' => array(), 'exclude' => array(), 'meta_key' => '', 'meta_value' => '', 'post_type' => 'pin', 'suppress_filters' => true);
$p = wp_parse_args($args, $defaults);
$get_pins = new WP_Query();
return $get_pins->query($p);
}
示例9: rec_epl_lu_single_download
function rec_epl_lu_single_download()
{
global $post, $epl_settings;
$unique_id = get_post_meta($post->ID, 'property_unique_id', true);
$tab_title = isset($epl_settings['epl_lu_group_title']) ? __($epl_settings['epl_lu_group_title'], 'epl') : __('Extra Info', 'epl');
$query = new WP_Query(array('post_type' => 'listing_unlimited', 'meta_query' => array(array('key' => 'property_unique_id', 'value' => $unique_id, 'compare' => '=='))));
if ($query->have_posts()) {
while ($query->have_posts()) {
$query->the_post();
$link = get_post_meta($post->ID, 'listing_unlimited_pdf', true);
?>
<div style="xxxdisplay:none" class="rec-panel-section-32 xxxfancybox-hidden">
<div id="xxxfancyboxID-section-32">
<?php
echo do_shortcode('[gravityform id="21" title="false" description="false" tabindex="33"]');
?>
</div>
</div>
<!--<h5 class="widget-sub-title download"><a href="#fancyboxID-section-32" class="rec-panel-section-32-popout-fancybox fancybox"><i class="fa fa-file-pdf-o"></i> Download Section 32</a></h5>-->
<?php
}
}
wp_reset_postdata();
}
示例10: wptouch_custom_latest_post_filter
function wptouch_custom_latest_post_filter($query_vars)
{
if (wptouch_is_showing_mobile_theme_on_mobile_device()) {
$settings = foundation_get_settings();
if (foundation_is_theme_using_module('custom-latest-posts') && $settings->latest_posts_page != 'none') {
$dummy_query = new WP_Query();
// the query isn't run if we don't pass any query vars
$dummy_query->parse_query($query_vars);
if ($dummy_query->is_page && count($query_vars) == 0) {
// Front page
$front_option = get_option('show_on_front', false);
if ($front_option == 'page') {
$front_page = get_option('page_on_front');
$dummy_query->queried_object_id = $front_page;
}
}
if (isset($dummy_query->queried_object_id) && apply_filters('foundation_is_custom_latest_posts_page', $settings->latest_posts_page == $dummy_query->queried_object_id)) {
if (isset($query_vars['paged'])) {
$paged = $query_vars['paged'];
} elseif (isset($query_vars['page'])) {
$paged = $query_vars['page'];
} else {
$paged = 1;
}
$query_vars = array('paged' => $paged, 'posts_per_page' => $settings->posts_per_page);
// Since we're modifying the query here, we need to prevent the custom landing page redirect from firing for this request (it'll think it's loading the homepage)
add_filter('wptouch_redirect_target', 'wptouch_return_false');
}
}
}
return $query_vars;
}
示例11: pricetable
/**
*
*/
public static function pricetable($atts, $content = null, $code = null)
{
if ($atts == 'generator') {
global $wpdb;
$prices_list = array();
$pricetables = $wpdb->get_results('SELECT ID, post_title FROM ' . $wpdb->posts . ' WHERE post_type = "pricetable"');
if (is_array($pricetables)) {
foreach ($pricetables as $key => $value) {
$prices_list[$value->ID] = $pricetables[$key]->post_title;
}
} else {
$price_list[0] = __('Please install Price Table plugin...', MISS_ADMIN_TEXTDOMAIN);
}
$option = array('name' => __('Blog Grid Layout', MISS_ADMIN_TEXTDOMAIN), 'value' => 'pricetable', 'options' => array(array('name' => __('Select Table', MISS_ADMIN_TEXTDOMAIN), 'desc' => __('Choose "Pricing Table" to use.', MISS_ADMIN_TEXTDOMAIN), 'id' => 'id', 'type' => 'select', 'options' => $prices_list), 'shortcode_has_atts' => true));
return $option;
}
extract(shortcode_atts(array('id' => ''), $atts));
$pricetable = new WP_Query();
$pricetable->query(array('post_type' => 'pricetable', 'post_id' => $id));
while ($pricetable->have_posts()) {
$pricetable->the_post();
$prices_list[get_the_ID()] = get_the_title();
$out = '[price_table id="' . $id . '"]';
}
return do_shortcode($out);
}
示例12: widget
function widget($args, $instance)
{
$cache = wp_cache_get('widget_dt_slider', 'widget');
if (!is_array($cache)) {
$cache = array();
}
if (!isset($args['widget_id'])) {
$args['widget_id'] = $this->id;
}
if (isset($cache[$args['widget_id']])) {
echo $cache[$args['widget_id']];
return;
}
ob_start();
extract($args);
$title = apply_filters('widget_title', empty($instance['title']) ? __('', 'engine') : $instance['title'], $instance, $this->id_base);
$category = empty($instance['category']) ? '' : $instance['category'];
$qty = empty($instance['qty']) ? '3' : $instance['qty'];
$excerpt_length = empty($instance['excerpt_length']) ? '0' : $instance['excerpt_length'];
$r = new WP_Query(array('posts_per_page' => $qty, 'no_found_rows' => true, 'post_status' => 'publish', 'ignore_sticky_posts' => true, 'category__in' => explode(',', $category)));
if ($r->have_posts()) {
?>
<?php
echo $before_widget;
echo do_shortcode('[engine_slider title="' . $title . '" category="' . $category . '" qty="' . $qty . '" autoplay="0" random="0" thumb_size="small" excerpt_length="' . $excerpt_length . '"]');
echo $after_widget;
// Reset the global $the_post as this query will have stomped on it
wp_reset_postdata();
}
$cache[$args['widget_id']] = ob_get_flush();
wp_cache_set('widget_dt_slider', $cache, 'widget');
}
示例13: wp_ajax_load_posts
/**
* Ajax function for loading posts by date and category
*/
function wp_ajax_load_posts()
{
if (!wp_verify_nonce($_GET['_wpnonce'], 'nonce-ajax-dropdown')) {
die('Go away!');
}
$year = isset($_GET['year']) ? $_GET['year'] : '';
$month = isset($_GET['month']) ? $_GET['month'] : '';
$args = array('year' => trim($year), 'monthnum' => trim($month), 'posts_per_page' => -1, 'orderby' => 'date', 'cat' => trim($_GET['cat'] != "-1") ? trim($_GET['cat']) : 0);
$ajaxsort = new WP_Query($args);
?>
<?php
if ($ajaxsort->have_posts()) {
?>
</div>
<?php
while ($ajaxsort->have_posts()) {
$ajaxsort->the_post();
?>
<?php
get_template_part('content', 'archives');
?>
<?php
}
?>
<?php
} else {
echo '<div align="center">Nothing Found!</div></nav>';
}
exit;
}
示例14: widget
/**
* Display widget content.
*
* @param array $args Display arguments including before_title, after_title, before_widget, and after_widget.
* @param array $instance The settings for the particular instance of the widget
*/
function widget($args, $instance)
{
extract($args);
$instance = wp_parse_args((array) $instance, $this->defaults);
$featured_page = new WP_Query(array('page_id' => $instance['page_id']));
echo $before_widget . '<div class="feature-page">';
if (!empty($instance['title'])) {
echo $before_title . apply_filters('widget_title', $instance['title'], $instance, $this->id_base) . $after_title;
}
if ($featured_page->have_posts()) {
while ($featured_page->have_posts()) {
$featured_page->the_post();
echo '<div class="' . implode(' ', get_post_class()) . '">';
if (!empty($instance['show_title'])) {
printf('<h4 class="entry-title"><a href="%s" title="%s">%s</a></h4>', get_permalink(), the_title_attribute('echo=0'), get_the_title());
}
//Show image
if (!empty($instance['show_image'])) {
printf('<a href="%s" title="%s" class="%s">%s</a>', get_permalink(), the_title_attribute('echo=0'), esc_attr($instance['image_alignment']), calibrefx_get_image(array('format' => 'html', 'size' => $instance['image_size'])));
}
if (!empty($instance['show_content'])) {
if (empty($instance['content_limit'])) {
the_content($instance['more_text']);
} else {
the_content_limit((int) $instance['content_limit'], esc_html($instance['more_text']));
}
}
echo '</div><!--end post_class()-->' . "\n\n";
}
}
echo '</div>' . $after_widget;
wp_reset_query();
}
示例15: widget
/**
* Front-end display of widget.
*
* @see WP_Widget::widget()
*
* @param array $args Widget arguments.
* @param array $instance Saved values from database.
*/
public function widget($args, $instance)
{
echo $args['before_widget'];
if (!empty($instance['title'])) {
echo $args['before_title'] . apply_filters('widget_title', $instance['title']) . $args['after_title'];
}
// The Query
$query_args = array('post_type' => 'post', 'post_per_page' => 5, 'meta_key' => 'views', 'orderby' => 'meta_value_num', 'order' => 'DESC', 'ignore_sticky_posts' => 'true');
$the_query = new WP_Query($query_args);
// The Loop
if ($the_query->have_posts()) {
echo '<ul>';
while ($the_query->have_posts()) {
$the_query->the_post();
echo '<li>';
echo '<a href="' . get_the_permalink() . '" rel="bookmark">';
echo get_the_title();
echo '(' . get_post_meta(get_the_ID(), 'views', true) . ')';
echo '</a>';
echo '</li>';
}
echo '</ul>';
} else {
// no posts found
}
/* Restore original Post Data */
wp_reset_postdata();
echo $args['after_widget'];
}