I’m working with wp 3.9.1 and plugin Custom Content Type Manager. I’m creating my own theme. I created a custom type called “aggregato”. I also use custom taxonomies. I then created a WP_query for my front-page:

$query = new WP_Query( array(
   'post_type' => array ('post', 'aggregato'),
   'cat' => '-1',
   'posts_per_page' => 12,
));

The query works, it returns 12 items of both the “post” and “aggregato” post types. Problem is that I want to format them differently. So when I use:

if ( is_singular('aggregato') ) {
    //my code
}

Nothing happens. It never enters, that condition is never return true. I don’t know what to do anymore. I used is_singular(), is_single(), $query->post-type, $post->post-type. Nothing. It just does not work.

Anybody has any idea? Any pointers? Please, help!

EDIT: the point is that using the codex and looking for answetrs on the web I was always sent to that particular function. It got some time to understand that it was not my case. I think that the question I posted was very clear. I was just, very simply, wrong.

3 Answers
3

I believe you are trying to check post type inside the Loop. To check the post type, try this:

global $post;
if('post' == $post->post_type ){
  // post stuff here
}
else{
  // aggregato stuff here
}

Alternatively, you can also use get_post_type() function to get post type of current post.

Leave a Reply

Your email address will not be published. Required fields are marked *