WordPress.org

Forums

is_singular() just won't work (3 posts)

  1. alevalentini
    Member
    Posted 9 months ago #

    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??

  2. catacaustic
    very awesome
    Posted 9 months ago #

    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.
    }
    endwhile;

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

  3. alevalentini
    Member
    Posted 9 months ago #

    I worked it out using

    $mytype=get_post_type();
    if ($mytype=='aggregato') {
    //magic
    }

    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!! :D

Reply

You must log in to post.

About this Topic