custom post types - Get the post_type of current taxonomy or category page

admin2025-01-07  7

I want to get post type of currently visited category or term. As for example, I have post_type post and category named Blog.

On Blog listing page, how can I get that this is a category of the post_type Post?

I want to get post type of currently visited category or term. As for example, I have post_type post and category named Blog.

On Blog listing page, how can I get that this is a category of the post_type Post?

Share Improve this question edited Oct 23, 2013 at 14:51 s_ha_dum 65.5k13 gold badges84 silver badges174 bronze badges asked Aug 20, 2013 at 5:49 Shaikh AezazShaikh Aezaz 1471 gold badge2 silver badges10 bronze badges 2
  • You can use get_post_type() function codex.wordpress.org/Function_Reference/get_post_type – Vinod Dalvi Commented Aug 20, 2013 at 6:11
  • I already used this function but it don't work when there is no post available :( – Shaikh Aezaz Commented Aug 20, 2013 at 9:03
Add a comment  | 

2 Answers 2

Reset to default 0

Both category and term are taxonomy. Taxonomy doesn't have post type. Post type is related to posts/pages/attachments/etc.

When you assign a category to a post, you can't say that that category has or related to specific post type.

If you want to receive post type of the first entity in the query, you will have to do something like this:

<?php

// fetch first post from the loop
the_post();

// get post type
$post_type = get_post_type(); 

// rewind the loop posts
rewind_posts();

?>

We can use this like

Reference : http://codex.wordpress.org/Function_Reference/get_post_type

转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1736252396a42.html

最新回复(0)