Support » Fixing WordPress » is_singular() just won't work

  • I’m using wp 3.9.1 with the plugin called Custom Content Type Manager.

    I created a custom type called “aggregato”. Now I am building a WP_query for my front-page. I select all posts of two types. It works.

    Then I want to show them differently. So inside the loop I tried

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

    But it just doesn’t work. I tried is_single(), I tried $query->post-type, $post->post-type… nothing.

    Any one has any idea on the reasons why this should not work??

Viewing 2 replies - 1 through 2 (of 2 total)
  • is_singular() works if the main page is for a singular post, so if you’re looping it’s not singular, so it will be false.

    I don’t see why $post->post_type doesn’t work, as that’s how I’d do it. Something like this…

    while (has_posts()): the_post();
    if ('aggregato' == $post->post_type) {
       // Do your stuff here.

    If that doesn’t work, post some code here and show us what is actually happening.

    I worked it out using

    if ($mytype=='aggregato') {

    Your pointers about the fact that is_singular() does not work for a multi results loop was the key to find the solution. Thanks a lot!! 😀

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘is_singular() just won't work’ is closed to new replies.