[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_related() – Implement [bw_related] shortcode

Description

Implement [bw_related] shortcode

To take out the hard work listing items which are related to the current item through "noderef" type fields Here we have the original shortcode from post ID 401 which is an instance of an "oik_shortcode"

 [bw_list post_type=shortcode_example meta_key=_sc_param_code meta_value=401] 
The lookup performed in bw_list is for posts of type "shortcode_example" with meta fields with a name of "_sc_param_code" that have a value of 401. In other words it lists all the "shortcode examples" which refer to this particular post. _sc_param_code is the name given to a noderef type field which references the "shortcode_example" post type. We 'hijacked' this field when defining the fields for the "shortcode_example" custom post type. It had previously been used for linking shortcode parameters to the shortcode. Rather than having to get the meta_value right in each usage of the shortcode we would like it to default to the current post id. We're going to change bw_get_posts() to achieve this for ALL post related shortcodes. BUT first we want to create the [bw_related] shortcode just to see how easy it is. ie. We'll code [bw_related post_type=shortcode_example meta_key=_sc_param_code] omitting the meta_value parameter. This shortcode can therefore also be used to lookup the $bw_fields / $bw_mapping table to find references to posts of the current post_type and therefore find the meta_key names to use thus enabling the shortcode to be coded as [bw_related] Now wouldn't that be nice? Note: the post_type defaults to the current post type… but that's not what we want except when we want to find links to other posts of the same type. We still need to know the value for the meta_key. We do need to know the current post type in order to find which fields refer to it.

Usage

bw_related( $atts, $content, $tag );

Parameters

$atts
( mixed ) optional –
$content
( mixed ) optional –
$tag
( mixed ) optional –

Returns

void

Source

File name: oik-fields/shortcodes/oik-related.php
Lines:
1 to 41 of 41
function bw_related( $atts=null, $content=null, $tag=null ) {
  //bw_trace2();
  //bw_backtrace();
  
  oik_require( "shortcodes/oik-list.php" );
  oik_require( "includes/bw_posts.php" );
  $post_type = bw_array_get( $atts, "post_type", null );
  $meta_key = bw_array_get( $atts, "meta_key", null );
  $atts['post_parent'] = bw_array_get( $atts, 'post_parent', 'no' );
  $tag = bw_array_get( $atts, "tag", null );
  $category_name = bw_array_get( $atts, "category_name", null );
  $by = bw_array_get( $atts, "by", null );
  if ( $tag ) {
    $atts['tag'] = bw_query_taxonomy_value( $tag ); 
  } elseif ( $category_name ) {
    $atts['category_name'] = bw_query_taxonomy_value( $category_name );  
  } elseif ( $by ) {
    $ids = bw_query_field_values( $by ); 
    $atts['post__in'] = bw_array_get_unkeyed( $ids );
    unset( $atts['by'] );
  } else {
    if ( $post_type && $meta_key ) {
      // they've specified the post type and meta_key so we don't have to look for it
    } else {
      $meta_key = bw_query_related_fields( $atts );
    }
    $atts['meta_value'] = bw_related_meta_value( $atts, $meta_key );
  } 
  $format = bw_array_get( $atts, "format", null );
  if ( $format === 'T') {
    oik_require( "shortcodes/oik-table.php");
    $result = bw_table( $atts );

  } elseif ( $format ) {
    oik_require( "shortcodes/oik-pages.php" );
    $result = bw_pages( $atts );
  } else {
    $result = bw_list( $atts ); 
  }  
  return( $result );  
}
 
 View on GitHub

Called by

    Invoked by

      Calls

      1 to 5 of 5
      • bw_array_get() – Return the array[index] or array->index (for an object) or a default value if not set
      • bw_query_field_values() – Return the field values for the given post
      • bw_query_related_fields() – Determine what we should be listing based on the current post
      • bw_query_taxonomy_value() – Determine the tag or category value to use if the given value is not a tag or category slug
      • bw_related_meta_value() – Determine a meta_value based on the field type, the specified meta_value and possibly the "meta_compare" parameter

      Call hooks

      Function name: bw_related
      Plugin ref: oik-fields – custom post type field APIs
      Version: 1.54.3
      Sourcefile: shortcodes/oik-related.php
      File ref: shortcodes/oik-related.php
      API type: shortcode
      Deprecated?: No
      API Letters: B,R

      Published: March 14, 2017 | Last updated: December 18, 2017

      Information

      Function name: bw_related
      Plugin ref: oik-fields – custom post type field APIs
      Version: 1.54.3
      Sourcefile: shortcodes/oik-related.php
      File ref: shortcodes/oik-related.php
      API type: shortcode
      Deprecated?: No
      API Letters: B,R

      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