AriRelated developer reference

AriRelated's shortcode, block attributes, template functions, filters, theme template, REST routes and WP-CLI commands.

  • Reference
  • AriRelated
  • 4 min read
  • Updated

This page covers AriRelated 0.1.0. Options you leave out use the values from Settings→AriRelated.

Shortcode: [arirelated]

[arirelated post_id="123" count="3" layout="list" columns="3" heading="More reading" image="1" image_size="thumbnail" excerpt="0" date="1" term="1" post_type="post,page" class="my-list"]
AttributeValuesDefault
post_idID of the post to find related posts for.Current post
countNumber of posts, 1–12.Number of posts setting
layoutgrid, list or text.Layout setting
columns1–6.Columns setting
headingHeading text. heading="" for none.Heading setting
image, excerpt, date, termShow or hide the image, excerpt, date and category: 1/0, true/false, yes/no.Show settings
image_sizeA registered image size name.Images setting
post_typeComma-separated post types to suggest from.Matching settings
classAn extra CSS class on the list.None

A post whose content contains the shortcode does not also get the automatic list.

Title Related Posts (AriRelated), category Widgets. It uses the postId context, so it works in Query Loop and single templates. It supports wide and full alignment, margin, padding, and text, background and link colours.

AttributeTypeDefault
useDefaultHeadingboolean: use the Heading settingtrue
headingstring, used when useDefaultHeading is false; empty for no heading""
countnumber; 0 = from settings0
layoutstring: "" (from settings), grid, list, text""
columnsnumber; 0 = from settings0
showImagebooleantrue
showExcerptbooleanfalse
showDatebooleantrue
showTermbooleantrue

Template functions

FunctionReturns
arirelated( array $args = array(), $post_id = null )Prints the list. $post_id defaults to the current post.
arirelated_get( array $args = array(), $post_id = null )The list as an HTML string.
arirelated_get_ids( $post_id = null, $count = 5 )An array of related post IDs: picks first, then automatic matches.

$args accepts heading, heading_tag (h2, h3, h4, p), count (1–12), layout (grid, list, text), columns (1–6), show_image, image_size, show_excerpt, excerpt_words, show_date, show_term, post_types (array), class and placement, which sets where Click stats counts the clicks: 1 automatic list, 2 inline links, 3 placed by hand (the default).

<?php arirelated( array( 'count' => 3, 'layout' => 'text', 'heading' => '' ) ); ?>

Theme template: arirelated/list.php

Create arirelated/list.php in your (child) theme and AriRelated uses it instead of its own list markup. The file has access to $items, $args, $source_id and $ids. Each item in $items has id, title, url, date, iso, excerpt, term and image (an <img> tag or empty). The arirelated_html filter does not run when the template is used. Keep data-arirelated-src, data-arirelated-place, data-arirelated-id and data-arirelated-k on your markup if you want clicks counted.

Filters

FilterParametersUse
arirelated_related_ids$ids, $post_id, $argsThe final list of related post IDs.
arirelated_scores$rows, $postAutomatic matches, best first: post ID => score, text, terms, fresh.
arirelated_min_score0.05, $postMinimum combined word and term score (0–1, before the freshness boost) a candidate needs.
arirelated_index_fields$fields, $postText indexed for a post, as array( text, weight ) pairs. Defaults: title 3, terms 2, excerpt 1.5, content 1.
arirelated_stopwords$words, $langWords ignored when indexing. $lang is the two-letter site language.
arirelated_indexed_post_types$typesPost types that are indexed and get the Related posts box. Default: every public type except attachments.
arirelated_item$item, $post, $argsOne item's data before it is printed.
arirelated_html$html, $source_id, $ids, $argsThe finished list HTML.

After changing arirelated_index_fields, arirelated_stopwords or arirelated_indexed_post_types, rebuild the index under Tools or with wp arirelated reindex.

REST API

Routes are under /wp-json/arirelated/v1/.

RouteParametersAccess and response
GET /posts/<id>id (integer, required), count (integer 1–12, default: Number of posts setting)Public for published, non-password-protected posts of a viewable type; otherwise needs edit_post. Returns an array of id, title, link, date (ISO 8601), excerpt, term, image (URL or null).
POST /clicks source ID and t target ID (integers, required), p placement (integer, default 1), k link signature (string)Public; used by the click counter. 204 when counted, 202 when ignored.
POST /indexrestart (boolean, default false)Needs manage_options. Indexes the next batch and returns done, total, running.
GET /wp-json/arirelated/v1/posts/123?count=4

Placement values are 1 (below posts), 2 (inline links) and 3 (block, shortcode, widget and template function).

WP-CLI

CommandWhat it does
wp arirelated reindexRebuilds the whole keyword index with a progress bar, then clears every cached list.
wp arirelated statusPrints Indexed: X of Y posts and the cache version.
wp arirelated related <id> [--format=<format>]Lists the post's picks (score picked) and its top ten automatic matches with id, title, score, text and terms. --format: table (default), json or csv.
wp arirelated clear-cacheDeletes every cached list.

Stored data

  • Tables {prefix}arirelated_index (keywords per post) and {prefix}arirelated_clicks (daily click totals).
  • Options arirelated_settings, arirelated_db_version, arirelated_index_state and arirelated_cache_version.
  • Post meta _arirelated_manual (picks), _arirelated_off, _arirelated_hide and _arirelated_cache (cached lists).
  • Scheduled events arirelated_index_batch and arirelated_prune_clicks (daily).

Deactivating stops the scheduled events and keeps the data. Deleting the plugin removes all of the above, on every site of a multisite network.

Still stuck?

Our helpdesk answers on working days, Norwegian time. Include your WordPress version, PHP version and the page address.

Submit a ticketor email info@arihub.com