A WordPress plugin for the PRC Platform that provides editorial tools and customizable blocks for managing related content relationships. Features an intuitive editor interface for manual curation and dynamic blocks for displaying related posts across your site with flexible layout options.
- Manual Related Posts Curation: Editor sidebar panel for manually selecting and managing related posts
- Related Posts Query Block: Dynamic block that displays related posts with customizable layouts
- Intelligent Fallback System: Automatically finds related content based on primary taxonomy terms when manual posts aren't specified
- Flexible Post Type Support: Configurable support for different post types
- Caching Integration: Built-in caching support with VIP cache integration
- Legacy Content Support: Handles migration and compatibility for older content
- WordPress 6.7+
- PHP 8.2+
- PRC Platform Core plugin
This plugin is part of the PRC Platform and should be installed alongside the core platform components.
- When editing a post, look for the "Related Posts" panel in the editor sidebar
- Use the panel to search and select posts you want to feature as related content
- Drag and drop to reorder the selected posts
- The manually selected posts will take precedence over automatically generated ones
- Add the "Related Posts Query" block to your content
- Configure the display options:
- Posts per page: Number of related posts to show (default: 5)
- Orientation: Vertical or horizontal layout
- Allowed blocks: Specify which blocks can be used in the query loop
When no manual related posts are specified, the plugin will automatically find related content by:
- Looking for posts with the same primary taxonomy term (using Yoast SEO primary category)
- Falling back to posts in the same category if primary term matching yields insufficient results
- Prioritizing recent content and excluding the current post
By default, the plugin works with the post
post type. You can extend support to additional post types using the filter:
add_filter( 'prc_platform__related_posts_enabled_post_types', function( $post_types ) {
$post_types[] = 'custom-post-type';
return $post_types;
});
You can retrieve related posts programmatically using the plugin's API:
// Get related posts for a specific post
$plugin = new \PRC\Platform\Related_Posts\Plugin();
$related_posts = $plugin->process( $post_id, $args );
The plugin includes built-in caching with the following defaults:
- Cache key:
relatedPosts
- Cache duration: 1 hour
- VIP cache integration: Automatic cache purging on content updates
Related posts data is stored in the relatedPosts
post meta field with the following schema:
{
"date": "string",
"key": "string",
"link": "string",
"permalink": "string",
"postId": "integer",
"title": "string",
"label": "string"
}
prc-related-posts/
├── prc-related-posts.php # Main plugin file
├── includes/ # Core PHP classes
│ ├── class-plugin.php # Main plugin class
│ ├── class-api.php # Related posts API
│ ├── class-loader.php # Hook loader
│ ├── class-plugin-activator.php
│ ├── class-plugin-deactivator.php
│ ├── utils.php # Utility functions
│ └── inspector-sidebar-panel/ # Editor sidebar component
└── blocks/ # Block components
├── class-blocks.php # Blocks registration
└── src/
└── related-posts-query/ # Related Posts Query block
├── index.js
├── block.json
└── class-related-posts-query.php
Navigate to the blocks directory and run:
cd blocks/
npm install
npm run build
prc_platform_on_update
- Clears cache when posts are updatedwpcom_vip_cache_pre_execute_purges
- Handles VIP cache purging
prc_platform__related_posts_enabled_post_types
- Modify supported post types
The plugin includes special handling for legacy content published before April 18, 2024. Posts older than this date will have custom related posts disabled unless explicitly enabled via the _legacy_related_posts_fixed
meta field.
The plugin implements a multi-level caching strategy:
- Object cache: Related posts are cached using WordPress object cache
- VIP integration: Automatic cache invalidation on VIP platform
- Preview protection: Cache is bypassed for logged-in users and preview contexts
Seth Rubenstein Pew Research Center [email protected]
GPL-2.0+
For technical support and bug reports, contact the development team at [email protected].