You appear to be a bot. Output may be restricted
Description
Wrapper to get_posts()When no parameters are passed processing should depend upon the context e.g for a 'page' it should list the child pages
- for a 'post' it should show related posts in the same category as the current post
Nos | $atts[‘post_type’] | $post->post_type | Default processing |
---|---|---|---|
1 | – | page | list child pages – first level only |
2 | – | post | list related posts – same categories |
3 | – | custom | none |
4 | page | page | as 1. |
5 | page | post | ? |
6 | page | custom | ? |
7 | post | page | ? |
8 | post | post | as 2. |
9 | post | custom | ? |
10-12 | custom | any | ? |
Usage
$array = bw_get_posts( $atts );
Parameters
- $atts
- ( array ) optional – shortcode parameters
Returns
array postsSource
File name: oik/includes/bw_posts.phpLines:
1 to 100 of 103
function bw_get_posts( $atts=null ) { // Copy the atts from the shortcode to create the array for the query // removing the class and title parameter that gets passed to bw_block() **?** 2013/07/01 - is this still done? $attr = $atts; bw_trace( $atts, bw_get_posts, __LINE__, __FILE__, "atts", BW_TRACE_DEBUG ); //bw_trace( $attr, __FUNCTION__, __LINE__, __FILE__, "attr" ); /* Set default values if not already set */ $attr['post_type'] = bw_array_get_dcb( $attr, 'post_type', NULL, "bw_global_post_type" ); $post_types = bw_as_array( $attr['post_type'] ); /* Allow specific post IDs to be defined in a variety of ways. */ $id = bw_array_get_from( $attr, array( "id", "post__in", "p", "page_id" ), null ); if ( !$id ) { if ( count( $post_types ) > 1 ) { $attr['post_type'] = $post_types; } else { // Only default post_parent for post_type of 'page' // This allows [bw_pages] to be used without parameters on a page // and to be used to list 'page's from other post types. // // Note: Pass a non-numeric value of post_parent to cause this parameter to not be used by get_posts() // if ( $attr['post_type'] == 'page' || $attr['post_type'] == 'attachment' ) { $attr['post_parent'] = bw_array_get_dcb( $attr, "post_parent", NULL, "bw_current_post_id" ); } /** If we're listing posts and the category is not specified then determine the category from the global post This finds "related" posts. Not sure how to find ANY post if that's what we want **?** 2013/06/21 */ if ( $attr['post_type'] == 'post' ) { $attr['category_name'] = bw_array_get( $attr, "category_name", NULL ); $attr['category'] = bw_array_get( $attr, "category", null ); if ( NULL == $attr['category_name'] && null == $attr['category'] ) { $categories = bw_get_categories(); if ( $categories ) { $attr['category_name'] = $categories; } else { // What do we do now? } } } $attr['numberposts'] = bw_array_get( $attr, "numberposts", -1 ); $attr['orderby'] = bw_array_get( $attr, "orderby", "title" ); $attr['order'] = bw_array_get( $attr, "order", "ASC" ); } } else { /* Allow the shortcode to specify a set of post IDs to load. id=1,2,3,4 or id="1 2 3 4" should load posts IDs 1, 2, 3 and 4 * Note: This currently overrides the "post__in" parameter * If $id was already an array then we must use 'post__in' */ $ids = bw_as_array( $id ); if ( is_array( $id ) || count( $ids ) > 1 ) { $attr['post__in'] = $ids; $attr['orderby'] = bw_array_get( $attr, "orderby", "post__in" ); unset( $attr['p'] ); } else { $attr['p'] = $id; $attr['page_id'] = $id; // Normally we don't need to worry about orderby or numberposts when we're only getting one post } if ( count( $post_types ) > 1 ) { $attr['post_type'] = $post_types; } } // Regardless of the post type, exclude the current post, if exclude= parameter NOT specified // If you want to retrieve the current post use exclude=-1 // // Note: This supports multiple IDs, comma separated $attr['exclude'] = bw_array_get_dcb( $attr, "exclude", NULL, "bw_current_post_id" ); /* * Support a post_name attribute */ $post_name = bw_array_get_from( $atts, ["post_name","post_name__in"], null ); if ( $post_name ) { $attr['post_name__in'] = bw_as_array( $post_name ); } // set suppress_filters to false when global bw_filters is set global $bw_filter; if ( isset( $bw_filter ) ) { $attr['suppress_filters'] = false; } bw_trace( $attr, bw_get_posts, __LINE__, __FILE__, "attr", BW_TRACE_DEBUG ); $bw_query = bw_array_get( $atts, "bw_query", null ); if ( $bw_query ) { $posts = _bw_get_posts( $attr ); } else { $posts = get_posts( $attr ); }View on GitHub View on Trac