当前位置: 首页>>代码示例>>PHP>>正文


PHP WP_Query::get_posts方法代码示例

本文整理汇总了PHP中WP_Query::get_posts方法的典型用法代码示例。如果您正苦于以下问题:PHP WP_Query::get_posts方法的具体用法?PHP WP_Query::get_posts怎么用?PHP WP_Query::get_posts使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在WP_Query的用法示例。


在下文中一共展示了WP_Query::get_posts方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: find

 /**
  * @param string $type
  * @param array $conditions
  * @return array
  */
 public function find($type = 'all', $conditions = array())
 {
     $conditions = array_merge(array('conditions' => array(), 'sort' => 'descending', 'limit' => null), $conditions);
     extract($conditions, EXTR_OVERWRITE);
     $conditions['limit'] = $limit;
     $conditions = $this->_parseQueryConditions($conditions);
     // debug($conditions);
     $WP_Query = new WP_Query($conditions);
     $posts = $WP_Query->get_posts();
     wp_reset_query();
     $result = array();
     switch ($type) {
         case 'first':
             $result = reset($posts);
             break;
         case 'list':
             foreach ($posts as $post) {
                 $result[$post->ID] = $post->post_title;
             }
             break;
         default:
             $result = $posts;
     }
     return $result;
 }
开发者ID:nikolaskarica,项目名称:bds-alliance,代码行数:30,代码来源:post.php

示例2: array

 function get_images($page, $per_page, $options = array())
 {
     $result = array();
     if (isset($options['images']) && $options['images']) {
         $ids = array_unique(array_map('intval', preg_split("/\\s*,\\s*/", $options['images'])));
         $query = new WP_Query(array('post__in' => array($ids), 'ignore_sticky_posts' => true, 'post_type' => 'any', 'post_status' => 'any', 'paged' => $page, 'posts_per_page' => $per_page));
         $posts = $query->get_posts();
     } else {
         if ($this->source['source'] == 'featured') {
             $posts = $this->get_posts($page, $per_page);
         } else {
             $posts = $this->get_attachments($page, $per_page);
         }
     }
     foreach ($posts as $post) {
         if ($post) {
             $image = $this->build_image($post, $options);
             if ($image) {
                 $result[] = $image;
                 $image->attachment_id = $post->ID;
             }
         }
     }
     return $result;
 }
开发者ID:jcwproductions,项目名称:jcwproductions-blog,代码行数:25,代码来源:source.class.php

示例3: getPosts

 public function getPosts()
 {
     /** By default wp will return all posts... override functionality so it returns no posts */
     if (isset($this->args['post__in']) && empty($this->args['post__in'])) {
         $this->posts = array();
         $this->pagination = array();
         return $this->posts;
     }
     if ($this->args == $this->argsHistory) {
         return $this->posts;
     }
     // push args to history
     $this->argsHistory = $this->args;
     //  query posts
     $wpQuery = new WP_Query($this->args);
     $this->posts = $this->generateProxies($wpQuery->get_posts());
     global $paged;
     global $wp_rewrite;
     $this->pagination = $this->calculatePagination(array('mid_size' => '1'), $wpQuery, $wp_rewrite, $paged);
     $this->pagination['found_posts'] = $wpQuery->found_posts;
     $this->pagination['max_num_pages'] = $wpQuery->max_num_pages;
     $this->pagination['post_count'] = $wpQuery->post_count;
     $this->pagination['posts_per_page'] = isset($wpQuery->query['posts_per_page']) ? $wpQuery->query['posts_per_page'] : 10;
     $this->pagination['page'] = isset($wpQuery->query['paged']) ? $wpQuery->query['paged'] : 1;
     $this->pagination['lower_index'] = ($this->pagination['page'] - 1) * $this->pagination['post_count'] + 1;
     $this->pagination['upper_index'] = $this->pagination['page'] * $this->pagination['post_count'];
     return $this->posts;
 }
开发者ID:mindgruve,项目名称:mg-press,代码行数:28,代码来源:QueryProxy.php

示例4: get_posts

 /**
  * Get posts.
  *
  * @param  stdClass $settings
  *
  * @return array
  */
 protected function get_posts($settings)
 {
     // By default we add posts per page key with the value -1 (all).
     if (!isset($settings->query['posts_per_page'])) {
         $settings->query['posts_per_page'] = -1;
     }
     // Prepare arguments for WP_Query.
     $args = array_merge($settings->query, ['post_type' => papi_to_array($settings->post_type), 'no_found_rows' => true, 'update_post_meta_cache' => false, 'update_post_term_cache' => false]);
     $query = new WP_Query($args);
     $posts = $query->get_posts();
     // Keep only objects.
     $posts = papi_get_only_objects($posts);
     $results = [];
     // Set labels.
     foreach ($posts as $post) {
         $obj = get_post_type_object($post->post_type);
         if (empty($obj)) {
             continue;
         }
         if (!isset($results[$obj->labels->menu_name])) {
             $results[$obj->labels->menu_name] = [];
         }
         $results[$obj->labels->menu_name][] = $post;
     }
     return $results;
 }
开发者ID:ekandreas,项目名称:papi,代码行数:33,代码来源:class-papi-property-post.php

示例5: get_info_item

function get_info_item($id)
{
    $id = base64_decode($id);
    $args = array('post_type' => "number", 'p' => $id);
    $query = new WP_Query($args);
    return $query->get_posts();
}
开发者ID:silasakk,项目名称:konumber,代码行数:7,代码来源:cart.php

示例6: tfuse_members

function tfuse_members($atts, $content = null)
{
    extract(shortcode_atts(array('post' => ''), $atts));
    $output = '';
    $post = explode(',', $post);
    $query = new WP_Query(array('posts_per_page' => -1, 'post_type' => 'member', 'post__in' => $post));
    $posts = $query->get_posts();
    if (!empty($posts)) {
        $output .= '<div class="our-team">';
        foreach ($posts as $post) {
            $job = tfuse_page_options('job', '', $post->ID);
            $image = wp_get_attachment_url(get_post_thumbnail_id($post->ID, 'post-thumbnails'));
            if (!empty($image)) {
                $image = TF_GET_IMAGE::get_src_link($image, 270, 270);
            }
            $output .= '<div class="col-lg-3 col-md-3 col-sm-6 col-xs-6">
                            <div class="image-our-team">
                                <img src="' . $image . '" alt="' . $post->post_title . '">
                            </div>
                            <h3>' . $post->post_title . '</h3>
                            <span class="function">' . $job . '</span>
                        </div>';
        }
        $output .= '</div>';
    }
    return $output;
}
开发者ID:aaronfrey,项目名称:PepperLillie-GVCO,代码行数:27,代码来源:members.php

示例7: tfuse_latest_reviews

function tfuse_latest_reviews($atts, $content = null)
{
    extract(shortcode_atts(array('title' => '', 'items' => ''), $atts));
    $query = new WP_Query(array('post_type' => 'review', 'orderby' => 'post_date', 'order ' => 'DESC', 'posts_per_page' => $items));
    $posts = $query->get_posts();
    $return_html = $img = '';
    if (!empty($posts)) {
        $return_html .= '<div class="widget widget_recent_entries">
                            <h3 class="widget-title">Latest Reviews</h3>
                            <ul class="side-postlist">';
        foreach ($posts as $post) {
            $post_image_src = wp_get_attachment_url(get_post_thumbnail_id($post->ID, 'post-thumbnails'));
            if (!empty($post_image_src)) {
                $get_image = new TF_GET_IMAGE();
                $img = $get_image->properties(array('class' => '', 'alt' => get_the_title($post->ID)))->width(62)->height(62)->src($post_image_src)->resize(true)->get_img();
            }
            $return_html .= '<li>';
            if (!empty($img)) {
                $return_html .= '<a href="' . get_permalink($post->ID) . '" class="post-thumbnail">
                                                ' . $img . '
                                            </a>';
            }
            $return_html .= '<a href="' . get_permalink($post->ID) . '" class="post-title">' . get_the_title($post->ID) . '</a>
                                        <span class="comments-link"><a href="' . get_permalink($post->ID) . '#comments">' . tfuse_get_comments(true, $post->ID) . '</a></span>
                                    </li>';
        }
        $return_html .= '</ul>
                        </div>';
    }
    return $return_html;
}
开发者ID:pinchpointer,项目名称:ppsitewordpress,代码行数:31,代码来源:latest_reviews.php

示例8: array

 function test_put()
 {
     RemoteSyncPlugin::instance()->install();
     $api = RemoteSyncPlugin::instance()->getApi();
     $data = array("post_name" => "some-slug", "post_type" => "page", "post_content" => "hello", "post_title" => "title", "post_excerpt" => "ex", "post_status" => "published", "post_parent" => NULL, "menu_order" => 0);
     try {
         $api->put(array("baseRevision" => "123", "slug" => "some-slug", "type" => "post", "data" => json_encode($data)));
     } catch (Exception $e) {
         $exceptionMessage = $e->getMessage();
     }
     $this->assertEquals($exceptionMessage, "Doesn't exist locally");
     $data = array("post_name" => "some-slug", "post_type" => "page", "post_content" => "hello", "post_title" => "title", "post_excerpt" => "ex", "post_status" => "published", "post_parent" => "", "menu_order" => 0, "meta" => array());
     $api->add(array("slug" => "some-slug", "type" => "post", "data" => json_encode($data)));
     $resData = $api->get(array("type" => "post", "slug" => "some-slug"));
     $this->assertEquals("98caf22f76c2d40eed50cf642db03e8b", $resData["revision"]);
     $data["post_content"] = "some new content";
     try {
         $api->put(array("slug" => "some-slug", "type" => "post", "baseRevision" => "wrong", "data" => json_encode($data)));
     } catch (Exception $e) {
         $exceptionMessage = $e->getMessage();
     }
     $this->assertEquals($exceptionMessage, "Wrong base revision, please pull.");
     $api->put(array("slug" => "some-slug", "type" => "post", "baseRevision" => "98caf22f76c2d40eed50cf642db03e8b", "data" => json_encode($data)));
     $q = new WP_Query(array("post_type" => "any", "post_status" => "any", "post_name" => "some-slug"));
     $posts = $q->get_posts();
     $this->assertEquals(1, sizeof($posts));
     $this->assertEquals($posts[0]->post_content, "some new content");
 }
开发者ID:tunapanda,项目名称:wp-remote-sync,代码行数:28,代码来源:test-RemoteSyncApi.php

示例9: tfuse_faq

function tfuse_faq($atts, $content = null)
{
    extract(shortcode_atts(array('post' => ''), $atts));
    $output = '';
    $post = explode(',', $post);
    $query = new WP_Query(array('posts_per_page' => -1, 'post_type' => 'faq', 'post__in' => $post));
    $posts = $query->get_posts();
    if (!empty($posts)) {
        foreach ($posts as $post) {
            $btn_title = tfuse_page_options('btn_title', '', $post->ID);
            $output .= '<div class="faq-article clearfix">
                            <div class="col-md-8 col-sm-7 col-xs-7 text">
                                <h2>Q: ' . $post->post_title . '</h2>
                                <p>' . $post->post_content . '</p>
                            </div>';
            if (!empty($btn_title)) {
                $output .= '<div class="col-md-3 col-md-offset-1 col-sm-5 col-xs-5 faq-button">
                                            <a href="' . tfuse_page_options('btn_link', '', $post->ID) . '" class="btn btn-yellow btn-donate-faq"><span>' . $btn_title . '</span></a>
                                        </div>';
            }
            $output .= '</div>';
        }
        // End IF Statement
    }
    return $output;
}
开发者ID:aaronfrey,项目名称:PepperLillie-GVCO,代码行数:26,代码来源:faq.php

示例10: wpSinglePostBySlug

function wpSinglePostBySlug($slug, $type)
{
    $query = new \WP_Query(array('pagename' => $slug, 'post_type' => $type));
    //$p = get_post($id);
    $post = $query->get_posts();
    return $post;
}
开发者ID:edwardpayton,项目名称:portfolio-site,代码行数:7,代码来源:helpers.php

示例11: get_posts

 /**
  * Get posts via GET.
  *
  * Posts with empty title will be ignored.
  *
  * GET /papi-ajax/?action=get_posts
  */
 public function get_posts()
 {
     $args = papi_get_qs('query') ?: [];
     $args = is_array($args) ? $args : [];
     $fields = papi_get_qs('fields') ?: [];
     $fields = is_array($fields) ? $fields : [];
     $query = new WP_Query(array_merge(['post_type' => ['post'], 'no_found_rows' => true, 'update_post_meta_cache' => false, 'update_post_term_cache' => false], $args));
     $posts = $query->get_posts();
     $posts = array_filter($posts, function ($post) {
         return !empty($post->post_title);
     });
     // @codeCoverageIgnoreStart
     usort($posts, function ($a, $b) {
         return strcmp(strtolower($a->post_title), strtolower($b->post_title));
     });
     // @codeCoverageIgnoreEnd
     if (!empty($fields)) {
         foreach ($posts as $index => $post) {
             $item = [];
             foreach ($fields as $field) {
                 $item[$field] = $post->{$field};
             }
             $posts[$index] = $item;
         }
     }
     wp_send_json($posts);
 }
开发者ID:nlemoine,项目名称:papi,代码行数:34,代码来源:class-papi-admin-ajax.php

示例12: test_ajax

function test_ajax()
{
    header("content-type: applications/json");
    $query = new WP_Query(array('numberposts' => 10, 'order' => 'DESC', 'orderby' => 'title', 'post_type' => 'post', 'thumbnail' => 'post'));
    echo json_encode($query->get_posts());
    die;
}
开发者ID:adbijan,项目名称:my-awesome-bootstrap-theme,代码行数:7,代码来源:custom-ajax.php

示例13: tpp_posts_widget

function tpp_posts_widget()
{
    $tpp_posts_query = new WP_Query();
    $tpp_posts_query->get_posts();
    ?>
	<h3>Posts on this page:</h3>
	<?php 
    if ($tpp_posts_query->have_posts()) {
        while ($tpp_posts_query->have_posts()) {
            $tpp_posts_query->the_post();
            ?>
	<a href="<?php 
            echo the_permalink();
            ?>
"
		title="<?php 
            echo the_title();
            ?>
"><?php 
            echo the_title();
            ?>
</a>
		(<?php 
            echo comments_number();
            ?>
)
	<?php 
        }
    }
    ?>
	<?php 
}
开发者ID:kirandash,项目名称:bijiplugindfly,代码行数:32,代码来源:top_posts_endStep1.php

示例14: get_banners

 public function get_banners($custom_args = array())
 {
     $args = array('posts_per_page' => -1, 'post_type' => 'banners', 'post_status' => 'publish');
     $query = new WP_Query(array_merge($args, $custom_args));
     return $query->get_posts();
     //return get_posts( wp_parse_args( $custom_args, $args ) );
 }
开发者ID:bunnywong,项目名称:freshlinker,代码行数:7,代码来源:Pro_Ads_Banners.php

示例15: jigoshop_product_list

function jigoshop_product_list($attributes)
{
    $options = Jigoshop_Base::get_options();
    $attributes = shortcode_atts(array('number' => $options->get('jigoshop_catalog_per_page'), 'order_by' => 'date', 'order' => 'desc', 'orientation' => 'rows', 'taxonomy' => 'product_cat', 'terms' => '', 'thumbnails' => 'show', 'sku' => 'hide'), $attributes);
    $args = array('post_type' => 'product', 'post_status' => 'publish', 'ignore_sticky_posts' => 1, 'posts_per_page' => $attributes['number'], 'orderby' => $attributes['order_by'], 'order' => $attributes['order'], 'meta_query' => array(array('key' => 'visibility', 'value' => array('catalog', 'visible'), 'compare' => 'IN')));
    if (!empty($attributes['taxonomy']) && !empty($attributes['terms'])) {
        $args['tax_query'] = array(array('taxonomy' => $attributes['taxonomy'], 'terms' => $attributes['terms'], 'field' => 'slug'));
    }
    $query = new WP_Query($args);
    remove_action('jigoshop_before_shop_loop_item_title', 'jigoshop_template_loop_product_thumbnail', 10);
    if ($attributes['thumbnails'] === 'show') {
        add_action('jigoshop_before_shop_loop_item', 'jigoshop_product_thumbnail', 10, 2);
    }
    if ($attributes['sku'] === 'show') {
        add_action('jigoshop_after_shop_loop_item_title', 'jigoshop_product_sku', 9, 2);
    }
    $result = jigoshop_render_result('shortcode/product_list', array('orientation' => $attributes['orientation'], 'products' => $query->get_posts(), 'has_thumbnails' => $attributes['thumbnails'] === 'show'));
    if ($attributes['sku'] === 'show') {
        remove_action('jigoshop_after_shop_loop_item_title', 'jigoshop_product_sku', 9);
    }
    if ($attributes['thumbnails'] === 'show') {
        remove_action('jigoshop_before_shop_loop_item', 'jigoshop_product_thumbnail', 10);
    }
    add_action('jigoshop_before_shop_loop_item_title', 'jigoshop_template_loop_product_thumbnail', 10, 2);
    return $result;
}
开发者ID:ashik968,项目名称:digiplot,代码行数:26,代码来源:product_list.php


注:本文中的WP_Query::get_posts方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。