Welcome, guest!

Feel free to read the blog, browse for themes, or join the club.

Easy way to add support for Custom Post types

  1. Ok, i'm really new to wordpress, been a drupal guy for a long time but everyone kept saying "try wordpress, it's way easy" and to some extent I'm starting to like it. Of course, there's a bit of a learning curve as I figure out where stuff is, what does what, ect.....

    But my first question and the source of most of my frustration right now, the thing I was hoping the hybrid system might help me with the most:

    Is there really no easy way to add support for custom post types into WP3?? It supports it, but it seems anytime you want to display custom post types you have to do a new page, make a new template, change everything.

    Isn't there an easy way to over ride the query to be something like IF anything other than a page SHOW it?

    For my needs it would be way easier just to filter out types I don't need when I don't need them then to have to rebuild everything to just list custom post types on archives, home page, category pages, ect....

    I'm probably missing something simple just because i'm not that familiar with WP. Any suggestions on how to just get it to query every post type save perhaps Pages?

  2. For the record custom post type is very advanced (and too overhyped) toy, I have yet to see someone say "hey, this is easy" about them. :)

    To query multiple post types (as far as I see in docs) you have to use array of post types for post_type argument, see
    http://codex.wordpress.org/Function_Reference/query_posts#Post_.26_Page_Parameters

  3. Well, lol, I won't jump in to hype custom types, seems that's quite a source of contention amongst wordpress users at the moment.

    I do think having the "one post to rule them all" methodology and using taxonomy only to categorize various types of info can be cumbersome and a bit difficult in and of it's self, but there are positives to that sort of arrangement too. It will limit WP as a CMS solution and i'm actually glad to see them "advancing" into custom taxonomies and types which will make WP a lot more powerful, but it is new and has limited support at the moment so...

    Looks like i would need to rewrite every query in every template to include each type, so perhaps I'll just go back to the default way of using taxonomy to classify everything for this project while I learn WP.

    But if anyone comes up with a way to get query_posts to default to "any" I'd still love to hear it. I'm so used to custom types it's a bit hard to get my head around not having it!

  4. Changing query in templates is not the only (or best) way to do it. It can also be filtered via hooks.

    This will default query to any - anything but post revisions.

    add_filter( 'request', 'query_any' );
    
    function query_any( $query ) {
    
        $query['post_type'] = 'any';
    
        return $query;
    }

    Note that I have no idea how many things such global change of default will break. :)

  5. Rarst, you are my new Hero!!!!

    That's exactly what i needed for now, thanks!

    But yeah, let's see what all it breaks, lol.... worth a try!

  6. LOL, well, ok the first thing it breaks is the admin listing of pages, when looking at posts you see everything, when looking at pages you see everything, when looking at custom types... yep, you see everything...

    Well, good try and maybe a good starting point for me as I start to toy with hooks..... Let's see what other solutions folks come up with.

  7. At request hook conditional tags ( is_ ) don't work yet so it is tricky to get control right. I didn't even try in this snippet...

    This page has overview of query mechanics for plugin developers and multiple suggestions on where you can filter query variables:
    http://codex.wordpress.org/Query_Overview

    Just go over it slowly and try to determine precisely under which conditions and at which stage you want to modify query, then implementing actual code is simple.

  8. You must be a logged-in exclusive member to view this reply.

  9. Thanks Justin!!!

    OH and PS, can't see how to set this as resolved?

  10. You must be a logged-in exclusive member to view this reply.

Reply

You must log in to post.

Limited Access

If you have an account, please take a moment to log in.

Non-exclusive members have limited access to the support forums.

To enjoy the full range of support, sign up for an exclusive membership in the theme club.

Support Forums

  • Hybrid Core (1,825 posts)
  • WordPress (4,093 posts)
  • Themes (6 posts)
  • Plugins (2,463 posts)
  • bbPress Themes (323 posts)
  • General Discussion (7,025 posts)
  • Bliss (256 posts)
  • Hybrid (28,641 posts)
  • Critical (133 posts)
  • Hybrid News (2,105 posts)
  • Hybrid Original (306 posts)
  • Leviathan (93 posts)
  • Life Collage (118 posts)
  • Old School (52 posts)
  • Outline (472 posts)
  • Skeleton (498 posts)
  • Structure (2,907 posts)
  • News (48 posts)
  • Options (10,402 posts)
  • Prototype (2,457 posts)
  • Retro-fitted (221 posts)
  • Trending (307 posts)
  • Visionary (778 posts)
  • Members (317 posts)
  • Cleaner Gallery (131 posts)
  • Get the Image (84 posts)
  • Message Board (23 posts)
  • Widgets Reloaded (28 posts)
  • Breadcrumb Trail (18 posts)
  • Query Posts (408 posts)
  • Hybrid Hook (47 posts)
  • Hybrid Hook Widgets (3 posts)
  • Hybrid Tabs (97 posts)