Description
Wrapper to WP_query::query()Sometimes we need to know more about the results of the query than just the posts We need to find the total number of posts in order to work out how many pages there are. This information is available from WP_Query when displaying paged content. This function implements most of get_posts() but it returns the WP_Query object that was used.
Usage
$array = _bw_get_posts( $args );Parameters
- $args
- ( array ) optional – parameters to get_posts or WP_query::query()
Returns
array $posts – the postsSource
File name: oik/includes/bw_posts.phpLines:
1 to 49 of 49
function _bw_get_posts( $args=null ) { $defaults = array( 'numberposts' => 5, 'category' => 0, 'orderby' => 'date', 'order' => 'DESC', 'include' => array(), 'exclude' => array(), 'meta_key' => '', 'meta_value' =>'', 'post_type' => 'post', 'suppress_filters' => true ); $r = wp_parse_args( $args, $defaults ); if ( empty( $r['post_status'] ) ) $r['post_status'] = ( 'attachment' == $r['post_type'] ) ? 'inherit' : 'publish'; if ( ! empty($r['numberposts']) && empty($r['posts_per_page']) ) $r['posts_per_page'] = $r['numberposts']; if ( ! empty($r['category']) ) $r['cat'] = $r['category']; if ( ! empty($r['include']) ) { $incposts = wp_parse_id_list( $r['include'] ); $r['posts_per_page'] = count($incposts); // only the number of posts included $r['post__in'] = $incposts; } elseif ( ! empty($r['exclude']) ) $r['post__not_in'] = wp_parse_id_list( $r['exclude'] ); $r['ignore_sticky_posts'] = true; // no_found_rows means don't count the number of found rows. // We need to set this to true most of the time - as we either get the lot or limit ourselves to numberposts // AND set it to false when we do want to know how many rows there are when paging. // no_found_rows = true - don't count the found rows // no_found_rows = false - do count the found rows // if ( $r['posts_per_page'] ) { $r['no_found_rows'] = bw_array_get( $args, "no_found_rows", false ); } else { $r['no_found_rows'] = bw_array_get( $args, "no_found_rows", true ); } $get_posts = bw_array_get( $args, "bw_query", null ); $posts = $get_posts->query( $r ); bw_trace2( $get_posts->post_count, "new WP_Query post_count", false, BW_TRACE_INFO ); bw_trace2( $get_posts, "new WP_Query", false, BW_TRACE_INFO ); bw_trace2( $get_posts->found_posts, "new WP_Query found_posts", false, BW_TRACE_INFO ); bw_trace2( $get_posts->max_num_pages, "new WP_Query max_num_pages", false, BW_TRACE_INFO ); //$result = array( $posts // , $get_posts // ); return( $posts ); }View on GitHub View on Trac
Invoked by
Calls
1 to 2 of 2
