Displaying Related post

$orig_post = $post;
global $post;
$categories = get_the_category($post->ID);
if ($categories) {
$category_ids = array();
foreach($categories as $individual_category) $category_ids[] = $individual_category->term_id;

'category__in' => $category_ids,
'post__not_in' => array($post->ID),
'posts_per_page'=> 2, // Number of related posts that will be shown.

How to Create Custom Post Types in WordPress

We can create your own custom post types and call them whatever we want. For example if you run a Loveseats website, then you would probably want to create a Loveseats post type. This post type can have different custom fields and even its own custom category structure. Other examples of post types are: Portfolio, Testimonials, Products, etc.

1. First register post type

function fullstack_cpt() {
    $args = array(
        'public' => true,
        'label'  => 'Loveseats Item',
         'menu_icon' => 'dashicons-category',
		'supports' => array( 'title', 'editor', 'thumbnail' )
    register_post_type( 'loveseats', $args );
add_action( 'init', 'fullstack_cpt' );

Custom post type Query with a custom taxonomy

Firs of all don’t use query_posts() ever, read more about it here: When should you use WP_Query vs query_posts() vs get_posts()?.

You have to use WP_Query to fetch posts what you need. Read documentation for it. In your case the query could be like this:

 $args = array( 
     'posts_per_page' => -1, 
     'orderby' => 'date',
     'order' => 'ASC', 
     'tax_query' => array(
            'taxonomy' => 'your_taxonomy_name',
            'field'    => 'slug', // term_id, slug  
            'terms'    => 'your_taxonomy_slug',
Available for work