1

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.

  • I don't understand your question. Do you need different stying on the frontpage, or on a single page, ie single.php – Pieter Goosen Jul 11 '14 at 7:23
  • Please post the entire code where you are calling is_singular() so we can see the context. – cfx Jul 11 '14 at 12:39
  • As said elsewhere, I was wrongly using it inside a loop with multiple results. – Alevalentini Jul 14 '14 at 8:32
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.

2

You are misunderstanding the is_singular() condition. The first line of it's codex states

This conditional tag checks if a singular post is being displayed

The key word there is displayed. It will only return true if the page that the user is currently looking at, is a single instance of the provided post type.

0

I believe you just want to loop through the posts returned by the query? You create a loop from the query like so:

if ( $query->have_posts() ) {
    while ( $query->have_posts() ) {
        $query->the_post();
        // Content for single post here
    }
}

Not the answer you're looking for? Browse other questions tagged or ask your own question.