[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 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 );
  }   
 
[1] [2] Next »
 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.8.2
Sourcefile: includes/bw_posts.php
File ref: includes/bw_posts.php
Deprecated?: No
API Letters: B,G,P

Recent plugin updates

oik-css v2.1.0 Update to oik-css v2.1.0 for the ability to style CSS and GeSHi output in documentation. ...
oik-types v2.3.0 Update to oik-types v2.3.0 for improved control over sort order on archives ...
UK-tides v3.1.0 UK-tides v3.1.0 now supports several additional ports. It's built with latest wp-scripts and shared libraries and tested with WordPress 6.1. ...
oik v4.8.2 Upgrade to oik v4.8.2 if you installed oik v4.8.1 from wordpress.org and found that the blocks were missing from the editor. ...
sb-chart-block v1.1.0 sb-chart-block v1.1.0 now uses chart.js v3.9.1. Tested with WordPress 6.0.1 and Gutenberg 13.8.2 ...

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: herb@bobbingwide.com

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-2023. All rights reserved.


Website designed and developed by Herb Miller of Bobbing Wide
Proudly powered by WordPress and oik-plugins
WordPress 6.1.1. PHP: 7.4.33. Memory limit: 768M