pfeifferNet

Related_Posts
in package

Handle the related posts frontend functionality.. - Given a post ID, return an array of related post IDs.

These related IDs are determined by shared categories and tags, with a preference for posts that share both.

  • The related post IDs are stored as an array in the post metadata on the target post.
Tags
since
5.0.0
since
5.13.0

Make singleton class.

since
6.7.0

Store array of related post ids as post meta, instead of in a transient.

Table of Contents

Constants

META_KEY  = 'pnet_related_posts'
Meta key name.

Properties

$common_related_posts  : Related_Posts
The instance of the Common_Related_Posts class.
$instances  : array<string|int, object>
The array of instances of this class and sub-classes.

Methods

get_ids()  : array<string|int, int>
Return the array of related post ids for the target post.
get_instance()  : object
Creates and/or returns the instance of this class.
__construct()  : void
Initialise the class.

Constants

META_KEY

Meta key name.

protected string META_KEY = 'pnet_related_posts'
Tags
since
6.7.0

Properties

$instances

The array of instances of this class and sub-classes.

protected static array<string|int, object> $instances = array()
Tags
since
5.13.0

Methods

get_ids()

Return the array of related post ids for the target post.

public get_ids(int $post_id) : array<string|int, int>
Parameters
$post_id : int

The id of the post to retrieve related posts for.

Tags
since
5.0.0
since
6.7.0

Refactor to use post meta instead of transients.

uses
Related_Posts::set_ids()
used-by
filter_related_posts()
used-by
filter_related_posts()
Return values
array<string|int, int>

Related post ids.

get_instance()

Creates and/or returns the instance of this class.

public static get_instance() : object
Tags
since
5.13.0
Return values
object

The instance of this class.

__construct()

Initialise the class.

protected __construct() : void
Tags
since
5.0.0
since
5.13.0

Refactor for singleton use.

since
6.7.0

Use the common related posts class to update the related posts list.

uses
Related_Posts

        
On this page

Search results