[oik] plugins.com

WordPress plugins and themes

  • Home
  • About
    • lazy shortcodes
    • smart shortcodes
    • oik base plugin
      • oik – donate
      • oik PayPal buttons
      • oik installation
      • oik Button Shortcode button
      • oik changelog
      • oik FAQ
      • oik plugins on SVN
      • oik plugins on GitHub
  • Plugins
    • oik base plugin
    • FREE oik plugins
    • WordPress plugins
    • Premium oik plugins
    • Bespoke oik plugins
  • Shortcodes
    • Shortcode examples
  • Blocks
    • Block examples
  • APIs
    • ALL action and filter hooks
  • Blog

bw_get_posts() – Wrapper to get_posts()

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 ?

As you can see from the table above the default behaviour for listing posts on pages and vice-versa is not (yet) defined

Usage

$array = bw_get_posts( $atts );

Parameters

$atts
( array ) optional – shortcode parameters

Returns

array posts

Source

File name: oik/includes/bw_posts.php
Lines:

1 to 94 of 94
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" );
  
  // 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_INFO );
  
  $bw_query = bw_array_get( $atts, "bw_query", null );
  if ( $bw_query ) {
    $posts = _bw_get_posts( $attr );
  } else {
    $posts = get_posts( $attr );
  }   
  bw_trace( $posts, bw_get_posts, __LINE__, __FILE__, "posts", BW_TRACE_INFO );
  return( $posts );
}
 

 View on GitHub View on Trac

Published: February 2, 2018 | Last updated: February 2, 2018

Information

Function name: bw_get_posts
Plugin ref: oik – oik information kit
Version: 4.1.2
Sourcefile: includes/bw_posts.php
File ref: includes/bw_posts.php
Deprecated?: No
API Letters: B,G,P

Recent plugin updates

oik-themes v1.4.0 

Update to oik-themes v1.4.0 to support Full Site Editing (FSE) themes. FSE themes, which are currently experimental, deliver block based templates and template parts.

 ...
oik-clone v2.0.1 oik-clone v2.0.1 contains a fix for a 500 internal server error being produced when cloning content with certain taxonomy terms. ...
SB Chart block v0.1.1 

Update to SB Chart block v0.1.1 for improved enqueing of the chart.js Javascript and better colours in the Gutenberg palette.

 ...
Slog v1.3.1 

Update to Slog v1.3.1 for a new Driver tab and improved display of charts grouping Elapsed times.

 ...
SB-Chart-Block v0.0.8 SB-Chart-Block v0.0.8, a WordPress single block plugin, supports 4 different chart types; Line, Bar, Horizontal bar and Pie. ...

Plugins

  • All Plugins
  • oik base plugin
  • FREE oik plugins
  • WordPress plugins
  • Premium oik plugins

Themes

  • FREE themes
  • Bespoke themes
  • Premium themes

Blocks

  • All Blocks
  • Block examples
  • About Blocks

Shortcodes

  • All Shortcodes
  • Shortcode examples
  • About Shortcodes

Reference

  • About APIs
  • All APIs
  • All Classes
  • All Files
  • All Hooks

Support

  • Contact
  • Cookies policy
  • Get API key
  • Privacy
  • Request support
  • Sitemap
  • Stay informed
  • Terms and Conditions
oik-plugins
Email: [email protected]

Weight shipping plugins

Find out which cart weight shipping plugin you need for your WooCommerce site.
Which cart weight based plugin do I need?

Site:  www.oik-plugins.com
© Copyright oik-plugins 2011-2021. All rights reserved.


Website designed and developed by Herb Miller of Bobbing Wide
Proudly powered by WordPress and oik-plugins