• Skip to main content
  • Skip to primary sidebar
  • Skip to footer

[oik] plugins.com

WordPress plugins and themes

  • 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

You appear to be a bot. Output may be restricted

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

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

Primary Sidebar

Information

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

Recent plugin updates

oik-fields v1.55.1
oik-fields v1.55.1 oik-fields v1.55.1 has been tested with WordPress 7.1. ...
oik v4.16.0
oik v4.16.0 Upgrade to oik v4.16.0 for many accessibility (a11y) improvements for both the front end and admin areas, plus a security fix. ...
oik-fields v1.55.0
oik-fields v1.55.0 Upgrade to oik-fields v1.55.0 for accessibility improvements to the featured image virtual field. ...
oik-css v2.4.0
oik-css v2.4.0 Upgrade to oik-css v2.4.0 for accessibility improvements for Low Color Contrast errors. ...
oik-unloader v0.4.0
oik-unloader v0.4.0 Update to oik-unloader v0.4.0 for improved accessibility of the active-plugins shortcode. Tested with WordPress 6.9 and PHP 8.4 ...

Footer

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


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

WordPress version: 7.1.2

Gutenberg version: 24.0.0

PHP version: 8.2.35