WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] is_post_type() within the loop? (5 posts)

  1. Anointed
    Member
    Posted 3 years ago #

    I have a loop that shows an array of posts from multiple post_types.

    I simply want a check to say 'if_post_type == "photogallery" ( do stuff) else (continue)

    This would allow me to style the photogallery posts within the loop different from the regular and other post_types inside the loop.

    This function does not work, but I can't find a replacement function that allows this logic.

    Can someone point me in the right direction?

    thank you

  2. demetris
    Member
    Posted 3 years ago #

    What you you need is is_singular():

    if (is_singular('photogallery')) {
        # Do some stuff.
    } else {
        # Do some other stuff.
    }
  3. Andrew Nacin
    Lead Developer
    Posted 3 years ago #

    If you're inside the loop and want to know about a specific post, then you'll want to look at get_post_type(). is_singular() refers to the loop as a whole.

  4. demetris
    Member
    Posted 3 years ago #

    Ouch. Apologies for the misinformation. Andrew Nacin is correct.

    So, the correct example would be:

    if (get_post_type() == 'photogallery') {
        # Do some stuff.
    } else {
        # Do some other stuff.
    }
  5. betadog
    Member
    Posted 2 years ago #

    Awesome. Just what I needed right now. Thank you Andrew, thank you demetris. You guys rock!

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.