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, __FUNCTION__, __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[bw_get_posts] = false; } bw_trace( $attr, __FUNCTION__, __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
Called by
1 to 15 of 16
- bw_accordion() – Display pages styled for jQuery accordion
- bw_attachments() – List attachments
- bw_get_by_metakey_array() – Load posts by meta_key array
- bw_jquery_enqueue_attached_scripts() – Enqueue any attached scripts
- bw_list() – Implement [bw_list] shortcode
- bw_load_noderef() – Load an array of node references
- bw_load_noderef2_flat() – Load flat posts
- bw_navi() – Implement [bw_navi] shortcode
- bw_pages() – Implement [bw_pages] shortcode
- bw_portfolio() – Display image links to PDF files For each .PDF file that is linked to an image pair them up and display with the image and the PDF file name as the selector and the PDF file name as the link.
- bw_table() – Display a table of information showing custom data and other content
- bw_tabs() – Implement the [bw_tabs] shortcode to display posts or pages styled for jQuery tabs
- bw_thumbs() – Display thumbnail links to pages
- bw_tree_func() – Build and format a tree
- Tests_prerequisites::get_posts() –
Invoked by
Calls
1 to 8 of 8
- bw_array_get() – Return the array[index] or array->index (for an object) or a default value if not set
- bw_array_get_dcb() – Return the array[index] or build the result by calling $callback, passing the $default as the arg.
- bw_array_get_from() – Return the value from a list of possible parameters
- bw_as_array() – Split a string into an array if necessary
- bw_get_categories() – Get the list of categories for this "post" as a string of slugs separated by commas
- bw_get_posts() – Wrapper to get_posts()
- bw_trace() – Log a simple trace record to the trace log file if tracing is active
- _bw_get_posts() – Wrapper to WP_query::query()
