Helping Organisations get organised!

Developer reference

Filters

  • lh_rpbt_auto_add_related (bool, default true): whether the list is appended to post content on classic templates. Return false to turn it off.
  • lh_rpbt_is_singular_template_slug (bool, $slug): whether the block is hooked after the post content in the block template with this slug.
  • lh_rpbt_get_related_post_types (array, $post; default array( 'post' )): the post types searched for related items.
  • lh_rpbt_get_applicable_post_types (array): post types that show related posts and get the per-post toggle. Defaults to viewable post types supporting the editor, except attachments and WooCommerce products.
  • lh_rpbt_return_term_ids (array $term_ids, $post, $taxonomies): the terms matched against.
  • lh_rpbt_get_excluded_ids_filter (array $ids, $post; default the current post): posts never returned.
  • lh_rpbt_get_included_ids_filter (false|array $ids, $post): when set, only these posts can be returned.
  • lh_rpbt_return_related_post_args (array $args, $content, $post): arguments for the automatic list and the block; set post_ids to choose the posts directly.
  • lh_rpbt_thumbnail_id_fallback (int $attachment_id, $post_id): the image shown for each related post.

All IDs and term IDs returned by these filters are validated as positive integers, and the query is built with prepared statements.

Overriding the template

Copy lh_rpbt-templates/default-template.php from the plugin to lh_rpbt-templates/default-template.php in the active (child) theme. It receives $the_query, a WP_Query of the related posts. The default output is a div.lh_rpbt-related_div.no-print holding an h3 and a ul.lh_rpbt-related_post_list; in block templates it is wrapped in the block’s own wrapper.

Stored data

  • Post meta lh_rpbt_hide (boolean, in the REST API): set when a post’s Show related posts toggle is off.
  • Option lh_rpbt-schema_version (per site): the upgrade routine’s progress.

Assets

Image size lh_rpbt_featured (200 by 150, cropped). Stylesheet handle lh_rpbt-style, enqueued only when a list is output; themes can override its rules.

If you like this plugin please consider making a donation to further development