14 Responses

  1. Marlon
    Marlon July 20, 2011 at 6:45 pm |

    Excelent as usual, thanks.

    Reply
  2. Mike Schinkel
    Mike Schinkel July 20, 2011 at 8:21 pm |

    This is great, nice article!

    OTOH you know where the get_post_type() doesn’t work reliably, and where it’s needed for certain types of plugin development is within the admin. I have a particularly gnarly set of functions I’ve written that does it’s best to tease out the $post_type by first teasing out the $post by first teasing out the $post_id. To get the $post_id requires looking into $_GET for $_GET['post'] or $_GET[$_GET['post_type']], or $_POST['post_ID'] or $_POST['post_id'], or in $wp_query->query_vars for ‘p’ $wp_query->query_vars[$wp_query->query_vars['post_type'], or get_page_by_path($qv['pagename'],OBJECT,’page’)->ID or get_page_by_path($_SERVER['REQUEST_URI']), or a bit of other nastiness. (Wish that WP core would simplify and then maintain this type of code for us.)

    But I digress. :)

    Reply
  3. Ray Gulick
    Ray Gulick July 21, 2011 at 12:31 pm |

    Thanks, Justin, for straightening this out. I saw that other article and thought it looked odd, and wondered what it was supposed to accomplish that couldn’t be accomplished by the code you’ve shared above; another reminder that you can’t believe everything you read on the internet.

    Reply
  4. goto10
    goto10 July 21, 2011 at 5:59 pm |

    Thanks Justin! DevPress is in my rotation now that you’re on board. Also, thanks to Mike. Definitely been there before, but wasn’t aware of all of the teasers you listed.

    Reply
  5. Weekly WordPress Review » WPCanada
  6. Chuck
    Chuck September 18, 2011 at 6:16 pm |

    How do you check if is_singular() is a custom post type or not if you don’t know the cpt name/slug? So if you’re checking, lets say in wp_head, if is_singular(‘post’) how do you also see if it’s a CPT?

    Reply
  7. chuckreynolds
    chuckreynolds September 18, 2011 at 6:21 pm |

    How do you check if is_singular() is a custom post type or not if you don’t know the cpt name/slug? So if you’re checking, lets say in wp_head, if is_singular(‘post’) how do you also see if it’s a CPT?

    Reply
  8. WordPress Custom Post Types Tutorials, Tools & Advice | Customize WordPress Blog
  9. John Mitchell
    John Mitchell November 3, 2011 at 2:57 pm |

    I am using the news template for the site. Have made a few mods to fit the needs. I do need to have a few pages that do not display any sidebar and use this added area as part of the page content. Have not been able to figure this out. What is an easy way to do this in news template? (Great template, by the way!) Thanks!

    Reply
  10. stylomat
    stylomat May 30, 2012 at 3:49 am |

    Oh my gooood!! Thank you so much – this was so important for my new wp project. thanks thanks thanks! :-)

    Reply
  11. Rabin
    Rabin June 12, 2012 at 4:42 am |

    Thanks Justin, for easy and clear explanation as usual.

    Reply
  12. Robbi
    Robbi August 23, 2012 at 7:02 am |

    Hi Justin, thanks for this! What would the solution be for an individual post within a custom post type? I’ve tried everything! :(

    Reply
  13. Rick
    Rick March 1, 2013 at 11:04 am |

    Thanks Justin! Needed to check if custom_post_type, so easy :)

    Cheers,

    Rick

    Reply

Leave a Reply

By submitting a comment here you grant this site a perpetual license to reproduce your words and name/Web site in attribution.

Please use your real name or a pseudonym (i.e., pen name, alias, nom de plume) when commenting. If you add your site name, company name, or something completely random, I'll likely change it to whatever I want.