https://github.com/humanmade/hm-related-posts
Related Posts (from HM Core) + Meta box for manually overriding dynamic selected posts.
https://github.com/humanmade/hm-related-posts
Last synced: about 1 year ago
JSON representation
Related Posts (from HM Core) + Meta box for manually overriding dynamic selected posts.
- Host: GitHub
- URL: https://github.com/humanmade/hm-related-posts
- Owner: humanmade
- License: gpl-2.0
- Created: 2013-09-15T20:01:33.000Z (almost 13 years ago)
- Default Branch: master
- Last Pushed: 2019-01-22T18:17:58.000Z (over 7 years ago)
- Last Synced: 2025-06-30T16:14:52.620Z (about 1 year ago)
- Language: PHP
- Size: 118 KB
- Stars: 12
- Watchers: 20
- Forks: 2
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
Related Posts
=============
This plugin provides a simple related posts function with the following features:
* ElasticPress integration (uses a "More Like This" query)
* Admin UI for manually overriding related posts
## Installation
```
composer require humanmade/related-posts
```
## Usage
The plugin exposes a single function that returns a list of post IDs.
### `HM\Related_Posts\get( int $post_id, array $args = [] )`
**$post_id** is the ID of the post to get related content for.
**$args** allows you some control over the posts that are returned:
- int **limit**: defaults to `10`
- array **post_types**: array of post types to limit results to. Defaults to `[ 'post' ]`
- array **taxonomies**: array of taxonomies to compare against. Defaults to `[ 'category' ]`
- array **terms**: array of `WP_Term` objects, results will match these terms
- array **terms_not_in**: array of `WP_Term` objects, results will not match these terms
- bool **ep_integrate**: if true then ElasticPress is used to get the results, Defaults to `defined( 'EP_VERSION' )`
### Custom post type support
To add related posts support to your custom post type simply declare the following:
`add_post_type_support( 'your-custom-post-type', 'hm-related-posts' );`
In addition to fine control the post types that have related posts support you can use the `hm_rp_post_types` filter.
```php
add_filter( 'hm_rp_post_types', function ( $post_types ) {
// your code goes in here
return $post_types;
} );
```
---------------------
Made with ❤️ by [Human Made](https://humanmade.com)