[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()

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, __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 );
  }   
 
[1][2]Next »
 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() –
[1][2]Next »

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()

    Call hooks

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

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

    Information

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

    Recent plugin updates

    oik-weight-zone-shipping v0.2.13 oik-weight-zone-shipping v0.2.13 has been tested with WooCommerce 10.1.2 and WordPress 6.8.2 ...
    SB Children Block v1.3.0 Upgrade to SB Children Block v1.3.0 for support for PHP 8.3 and PHP 8.4  ...
    oik v4.15.3 Update to oik v4.15.3 for a couple of security fixes. Tested with WordPress 6.8.2 ...
    oik-privacy-policy v1.4.9 Update to oik-privacy-policy v1.4.9 for a security fix. Tested with WordPress 6.8.2 and PHP 8.3 and PHP 8.4 ...
    oik-nivo-slider v1.17.0 oik-nivo-slider v1.17.0 introduces the Nivo slider block - oik-nivo-slider/nivo. ...

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


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

    WordPress version: 6.8.3

    Gutenberg version: 21.7.0

    PHP version: 8.2.29