News or e-commerce websites, which have multiple blog posts or products, usually need Related Posts. Adding related posts to your posts brings some advantages of SEO and user experience. However, using plugins that create related posts automatically may not satisfy when you want to choose some particularly related posts. In this tutorial, we'll use Meta Box to create related posts that you can choose manually.
Related posts, as its name says, are the posts which have intimate content with the current post. Its content may be a kind of additional information, inline, suggestion, etc.
Related posts are often displayed in a group and put at the end, sidebar, or even in the middle of the post. The number and position of the related posts depend on your website design.
For visitors, having related posts gives them suggestions to read more related content which they may need. In the event the current post does not have enough information, related posts are a good way to get more.
To the website owners, the related posts create or increase a significant number of internal links on your site. It pulls the visitors to stay longer on your site at the same time. This thing helps you improve multiple website indicators such as the bounce rate, page view, time on site, and so on.
Normally, most tools set related posts automatically based on the keywords, tags, categories, or taxonomies. It might be not precise, especially when your marketing team wants particularly related posts to be prior on the list. In that case, choosing related posts manually will be the best way.

What is Meta Box? What is the Post Field?
Meta Box is a light and simple plugin but powerful to create and configure custom fields in WordPress. In case you are not familiar with Meta Box yet, this post is for your reference.
Meta Box supports more than 40 types of custom fields, means that almost the fields everyone needs. Meta Box also supports fields that associate databases from posts, pages, and custom post types in WordPress.
In this post, we are going to use a special field type named Post Field, which allows us to link to posts, to create related posts.
Post Field is a field that allows you to choose one or multiple posts. It may be displayed in several styles as select, checkbox or radio. Using Post Field allows us to choose a particular post, even in different post types, manually.
Step 1: Install Meta Box Plugin
Firstly, you need to install and activate the Meta Box plugin on your WordPress site. The plugin is free and available on wordpress.org:
If you are not familiar to PHP or don’t want to touch any line of code, you should install a premium extension from Meta Box in addition, Meta Box Builder. This extension (it is a plugin as well) provides you an intuitive user interface to create and configure custom fields without coding. Even when you have no knowledge of PHP, the execution is really easy. Otherwise, you can save money with the free Online Generator tool.
If you are a developer, you may create fields by code. That means you need to install the Meta Box plugin only.
FYI, here is the instruction to install and activate plugins.
Step 2: Create and Configure Post Field
When you installed Meta Box Builder, creating a Post Field is very easy for everyone.
In the Admin Dashboard, go to the Meta Box → Custom Fields → Add New.
In the displaying screen of Edit Field Group, name your field group in Title field, set it an ID, then click on Update. You have a field group to hold the Post Field now.
Next, click Add Field button and select Post in the drop-down menu. A post field will appear automatically inside the created field group.
Now, we configure the post field. There are some notices about setting in this step:
Description & Post Type:
In this field, you may give some instruction on how to choose the posts in the Lable Description. E.g. I made it be “Choose 3 Related Posts” to request the writers choose enough three posts to be related.
If you have several post types on your site, you must indicate the right post type you want to be related to (pay attention to this, no. 1). For instance, if the related posts you want are in the type of a custom post type, Products, you must choose Products here. If the related post is in the type of default blog posts, you must choose Post here. You can choose more than 1 post type.
Tip:
With the Post Type option, you absolutely can choose another post type’s posts to be related. e.g products can be related to a blog post.
Take the case of a travel agency that sells tours to go to Thailand where each tour is a product page (its post type is Product). If they have a blog post that shares travel experiences and tips in Thailand, by set post type Product here, they can put some Thailand tours to be related posts to suggest people buy their tours. Such a good way to increase sales!
Field Type:
This field stipulates how the post field show the posts inside. There are several styles to show, ones of the most common styles are:
Personally, I prefer Select Advanced because it is neat and provides searching. If we have a significant number of posts, e.g. over 1,000 posts, scrolling to find a post may be dull. Otherwise, if you set pages to be related (there are few pages), scrolling of Checkbox list or Radio may work.
Display the "Select All | None" button:
Only tick this box when your field is in the Checkbox list style. That makes a “Toggle All” button appears allowing you to choose/unchoose all the posts with one click.
After configuring all options in the Field tab of the Edit Field Group screen, move to the Settings tab. In the Post Types field, choose a post type of the post where you want to show related posts (pay attention to this, no. 2).
Finally, click on Save Changes to save all the settings.
Instead of using Meta Box Builder to create Post Field as above, you may code and take a look at my below code. This is a gist generated automatically by Meta Box Builder plugin after creating Post Field. If you put it into the function.php
file of your theme, you will get the same result as mine.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
add_filter( 'rwmb_meta_boxes', 'your_prefix_register_meta_boxes' ); | |
function your_prefix_register_meta_boxes( $meta_boxes ) { | |
$meta_boxes[] = array ( | |
'title' => 'Related Post', | |
'id' => 'related-post', | |
'post_types' => array( | |
0 => 'post', | |
), | |
'context' => 'normal', | |
'priority' => 'high', | |
'fields' => array( | |
array ( | |
'id' => 'related_posts', | |
'type' => 'post', | |
'name' => 'Related Posts', | |
'desc' => 'Choose 3 Related Posts', | |
'post_type' => array( | |
0 => 'post', | |
1 => 'page', | |
), | |
'field_type' => 'select_advanced', | |
'multiple' => true, | |
'required' => 1, | |
), | |
), | |
); | |
return $meta_boxes; | |
} |
Now, back to the edit page of your post, which has the post type you chose to show related posts (the attention point no.2). Move to where you place the created field “Related Posts” and click on there. A list of posts will show as following:

This list includes all the posts in the post types which you chose (attention point no.1). Just click on the post title, then press Update. Now, your post had related posts.
The created Post Field saves the IDs of chosen related posts. It returns an array of values as follows:
array (size=3) 0 => string '36' (length=2) 1 => string '25' (length=2) 2 => string '29' (length=2)
So, we use this function to get the value of posts:
$post_ids = rwmb_meta( $field_id ); foreach ( $post_ids as $post_id ) { echo '<p>'. get_the_title( $post_id ). '</p>'; }
In there:
$field_id
: ID of the Post Field which we set$post_ids
: The array of post IDs that the Post Field returns
We can customize or export data by IDs. It means that you can get any information from the related posts such as title, thumbnail, excerpt to show on your website. I did get all of them (title, thumbnail, and excerpt) in this instruction.
Put the below gist to the single.php
file if your post type is post. If your post is another custom post type, create a file named single-{custom_post_type_slug}.php
and put the gist into there. Read more about creating a custom post type here.
Source code:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$field_id = 'related_posts'; | |
$related_posts = rwmb_meta( $field_id ); | |
if (isset($related_posts)) { ?> | |
<div id="relatedPosts" class="related-posts"> | |
<h3 class="related-posts-headline"><em>You might also like</em></h3> | |
<div class="related-posts-items jp-related-posts-grid"> | |
<?php foreach ($related_posts as $related_post) { ?> | |
<div class="related-post-item"> | |
<a class="related-post-a" href="<?php echo get_the_permalink($related_post); ?>" title="<?php echo get_the_title($related_post); ?>" rel="nofollow"> | |
<img class="related-post-img" src="<?php echo get_the_post_thumbnail_url($related_post, 'thumbnail'); ?>" alt="<?php echo get_the_title($related_post); ?>"> | |
</a> | |
<h4 class="related-post-title"> | |
<a class="related-post-a" href="<?php echo get_the_permalink($related_post); ?>" title="<?php echo get_the_title($related_post); ?>" rel="nofollow"><?php echo get_the_title($related_post); ?></a> | |
</h4> | |
<p class="related-post-excerpt"><?php the_excerpt($related_post); ?></p> | |
</div> | |
<?php } ?> | |
</div> | |
</div> | |
<?php } ?> |
Final Words
That’s how to add related posts to WordPress posts using Meta Box plugin. With this method, you may customize the related post as you want and choose a particular post as well. Hope that it may help you to give your visitor more useful content, increase SEO score as well as sales.
Other case studies you might be interested in
- Create A Dynamic Landing Page in WordPress Using Custom Field
- Create a Filter to Find Hotels by Location
- Create an OTA Website Like Booking.com with Meta Box Plugin - P1: Create a Page to Introduce Hotel Rooms
- Create an OTA Website Like Booking.com with Meta Box Plugin - P2: Create Filters on the Archive Page
- Create an OTA Website Like Booking.com with Meta Box Plugin - P3: Create Filters for Single Hotel Pages
- Create Dynamic Favicon in WordPress using Meta Box plugin
- Create Posts Series in WordPress Using Meta Box
- Display a User List On the Frontend with Meta Box
- Display The Latest Products Section - P2 - Using Meta Box and Elementor
- Display The Latest Products Section - P3 - Using Meta Box And Oxygen
- How to Add Custom Fields to Display Banners using Meta Box Plugin
- How to Add Guest Authors and Guest Posts - Using Meta Box
- How to Add Related Posts to WordPress Using Meta Box
- How to Build a Hotel Booking Website Using Meta Box - P1
- How to Build a Hotel Booking Website Using Meta Box - P2 - Booking Page in Backend
- How to Build a Hotel Booking Website Using Meta Box - P4 - Booking Management Page
- How to Build a Hotel Booking Website Using Meta Box – P3 – Booking Page for Customer
- How to Create a Classified Ads Website using Meta Box
- How to create a FAQs page - P5 - Using Meta Box and Breakdance
- How to Create a Product Page - P2 - Using Meta Box and Oxygen
- How to Create a Product Page - P3 - Using Meta Box and Bricks
- How to Create a Product Page - P4 - Using Meta Box and Elementor
- How to Create a Product Page - P5 - Using Meta Box and Gutenberg
- How to Create a Product Page - P6 -Using Meta Box and Breakdance
- How to Create a Product Page - P7 - Using Meta Box + Kadence
- How to Create a Product Page - P8 - Using Meta Box and Brizy
- How to Create a Product Page using Meta Box Plugin
- How to Create a Recipe - P2 - Using Meta Box and Oxygen
- How to Create a Recipe - P3 - Using Meta Box and Elementor
- How to Create a Recipe - P4 - Using Meta Box and Bricks
- How to Create a Recipe - P5 - Using Meta Box and Zion
- How to Create a Recipe - P6 - Using Meta Box and Brizy
- How to Create a Recipe - P7 - Using Meta Box and Breakdance
- How to Create a Recipe with Meta Box Plugin
- How to Create a Simple Listing - P2 - Using Meta Box and Bricks
- How to Create a Team Members Page - P1- Using Meta Box and Elementor
- How to Create a Team Members Page - P2 - Using Meta Box and Oxygen
- How to Create a Team Members Page - P3 - Using Meta Box and Bricks
- How to Create a Team Members Page - P4 - Just Meta Box
- How to Create a Team Members Page - P6 - using Meta Box and Breakdance
- How to Create a Video Gallery Page - P2 - Using Meta Box + Bricks
- How to Create a Video Gallery Page - P3 - Using Meta Box and Breakdance
- How to Create a Video Gallery Page - P4 - Using Meta Box + Elementor
- How to Create a Video Gallery Page - P5 - Using MB Views
- How to Create a Video Gallery Page Using Meta Box + Oxygen
- How to Create ACF Flexible Content Field with Meta Box
- How to Create an Auto-Updated Cheat Sheet in WordPress
- How to Create an FAQs Page - P1 - Using Meta Box and Elementor
- How to create an FAQs page - P2 - Using Meta Box and Oxygen
- How to create an FAQs page - P4 - Using Meta Box and Bricks
- How to Create an FAQs Page -P3- Using Meta Box
- How to Create Buttons with Dynamic Link using Custom Fields
- How to Create Category Thumbnails & Featured Images Using Custom Fields
- How to Create Download and Preview Buttons - P1 - Using Meta Box and Bricks
- How to Create Download and Preview Buttons - P2 - Using Meta Box and Oxygen
- How to Create Download Buttons Using Custom Fields with Meta Box Plugin
- How to Create Menus for Restaurants - P1 - Using Meta Box and Elementor
- How to Create Menus for Restaurants - P2- Using Meta Box and Bricks
- How to Create Online Admission Form for School or University
- How to Create Online Reservation Form for Restaurants using Meta Box
- How to Create Relationships - P1 - Using Meta Box and Oxygen
- How to Create Relationships - P2 - Using Meta Box and Bricks
- How to Create Relationships - P3 - Using MB Views
- How to Create Taxonomy Thumbnails & Featured Images - P2 - Using Meta Box and Oxygen
- How to Create Taxonomy Thumbnails & Featured Images - P3 - Using Meta Box and Bricks
- How to Display Images from Cloneable Fields - P1 - with Gutenberg
- How to Display Images from Cloneable Fields - P2 - with Oxygen
- How to Display Images from Cloneable Fields - P3 - with Elementor
- How to Display Images from Cloneable Fields - P4 - with Bricks
- How to Display Opening Hours for Restaurants - P1 - Using Meta Box + Gutenberg
- How to Display Opening Hours for Restaurants - P2 - Using Meta Box and Oxygen
- How to Display Product Variations - P1 - Using Meta Box and Gutenberg
- How to Display Product Variations - P2 - Using Meta Box and Oxygen
- How to Display Product Variations - P3 - Using Meta Box and Bricks
- How to Display The Latest Products - P5 - Using Meta Box and Bricks
- How to Display the Latest Products - P6 - using Meta Box and Breakdance
- How to Display the Latest Products - P7 - Using Meta Box + Kadence
- How to Display the Latest Products Section - P4 - Using Meta Box + Zion
- How to Display the Most Viewed Posts - P1 - using MB Views
- How to Display the Most Viewed Posts - P2 - using Meta Box and Oxygen
- How to Display the Most Viewed Posts - P3 - Using Meta Box and Bricks
- How to Filter Posts by Custom Fields - P2 - using Meta Box and FacetWP
- How to Manually Reorder Posts with Meta Box
- How to Show Featured Restaurants on Homepage - P1 - Meta Box + Elementor + WP Grid Builder
- How to Show Posts With a Specific Criteria - P3 - Using MB Views
- How to Show Posts with Specific Criteria - P1 - Using Meta Box and Bricks
- How to Show Posts with Specific Criteria - P2 - Using Meta Box and Oxygen
- How to Show Posts with Specific Criteria - P4 - Using Meta Box + Breakdance
- How to Show Posts with Specific Criteria - P5 - Using Meta Box and Elementor
- How to Show the Featured Restaurants - P3 - using Meta Box and Oxygen
- How to Show the Featured Restaurants - P4 - Using MB Views
- How to Show the Featured Restaurants - P5 - Using Meta Box and Elementor
- How to Show the Featured Restaurants - P6 - Using Meta Box and Zion
- How to Show the Featured Restaurants Section - P2 - Using Meta Box and Bricks
I have set my posts to display recent posts from the post category. When I have a post with more than one category, I get 2 instances of recent posts. Is there a way to tell the plugin to limit to the first category instance? thanks!
If you are using a plugin to display recent posts, you can contact plugin support to ask for help with this case.
If you are using custom code to display recent posts from categories, just get the second category. Refer to this documentation https://developer.wordpress.org/reference/functions/get_the_category/