L
L
Lorem Ipsum2018-04-25 12:39:43
WordPress
Lorem Ipsum, 2018-04-25 12:39:43

How to display category entries in single.php?

Hello!
There is a custom record type - Directory. It is necessary to display on the page single-catalog.php Records that belong to this product category (Similar products). I can not do it, Google does not help. get_queried_object()->term_id doesn't work.

<?php
                global $post;
                $args     = array(
                  'numberposts' => 3,
                  'offset'      => 0,
                  'category'    => get_queried_object()->term_id
                );
                $myposts  = get_posts( $args );
                foreach ( $myposts as $post ):
                  setup_postdata( $post );
                  //...
                  ?>

How can it be implemented?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Max Medar, 2018-04-25
@GeorgeGeorge

The current category, if it is the default category, can be retrieved via get_the_category() .
But is your custom type bound to category?
Also in the parameters to get_posts() you need to specify the type of your post: 'post_type' => 'catalog', or what type you need.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question