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"]
| Attribute | Values | Default |
|---|---|---|
post_id | ID of the post to find related posts for. | Current post |
count | Number of posts, 1–12. | Number of posts setting |
layout | grid, list or text. | Layout setting |
columns | 1–6. | Columns setting |
heading | Heading text. heading="" for none. | Heading setting |
image, excerpt, date, term | Show or hide the image, excerpt, date and category: 1/0, true/false, yes/no. | Show settings |
image_size | A registered image size name. | Images setting |
post_type | Comma-separated post types to suggest from. | Matching settings |
class | An extra CSS class on the list. | None |
A post whose content contains the shortcode does not also get the automatic list.
Block: arirelated/related-posts
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.
| Attribute | Type | Default |
|---|---|---|
useDefaultHeading | boolean: use the Heading setting | true |
heading | string, used when useDefaultHeading is false; empty for no heading | "" |
count | number; 0 = from settings | 0 |
layout | string: "" (from settings), grid, list, text | "" |
columns | number; 0 = from settings | 0 |
showImage | boolean | true |
showExcerpt | boolean | false |
showDate | boolean | true |
showTerm | boolean | true |
Template functions
| Function | Returns |
|---|---|
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
| Filter | Parameters | Use |
|---|---|---|
arirelated_related_ids | $ids, $post_id, $args | The final list of related post IDs. |
arirelated_scores | $rows, $post | Automatic matches, best first: post ID => score, text, terms, fresh. |
arirelated_min_score | 0.05, $post | Minimum combined word and term score (0–1, before the freshness boost) a candidate needs. |
arirelated_index_fields | $fields, $post | Text indexed for a post, as array( text, weight ) pairs. Defaults: title 3, terms 2, excerpt 1.5, content 1. |
arirelated_stopwords | $words, $lang | Words ignored when indexing. $lang is the two-letter site language. |
arirelated_indexed_post_types | $types | Post types that are indexed and get the Related posts box. Default: every public type except attachments. |
arirelated_item | $item, $post, $args | One item's data before it is printed. |
arirelated_html | $html, $source_id, $ids, $args | The 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/.
| Route | Parameters | Access 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 /click | s 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 /index | restart (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
| Command | What it does |
|---|---|
wp arirelated reindex | Rebuilds the whole keyword index with a progress bar, then clears every cached list. |
wp arirelated status | Prints 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-cache | Deletes 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_stateandarirelated_cache_version. - Post meta
_arirelated_manual(picks),_arirelated_off,_arirelated_hideand_arirelated_cache(cached lists). - Scheduled events
arirelated_index_batchandarirelated_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.