WordPress.org

Ready to get started?Download WordPress

Forums

Array for 'all' custom post types? (6 posts)

  1. Stefan83
    Member
    Posted 1 year ago #

    When creating a query array for custom post types, is there a way of including all types without having to list them all as they are created?

    for example

    'post_type' => array ('post', 'blog-item', 'company-spotlight', 'ebook', 'podcast', 'photo-gallery', 'presentation-slide', 'video', 'white-paper'),

    would look something like:

    'post_type' => array ('post', 'ALL_CUSTOM_POST_TYPES'),

  2. wpcanyon
    Member
    Posted 1 year ago #

    Try this.

    $post_types = get_post_types( '','names' );
    ...
    'post_type' => $post_types,
  3. Stefan83
    Member
    Posted 1 year ago #

    Thanks wpcanyon, so there isn't an array for all custom post types?

  4. wpcanyon
    Member
    Posted 1 year ago #

    Ahh sorry, i was wrong. Just remembered there's this...

    'post_type' => 'any',
  5. Stefan83
    Member
    Posted 1 year ago #

    Awesome, thanks wpcanyon!

    I also want to register the following function for adding tags metaboxes to 'any' post type but it doesn't work? Any ideas?

    function demo_add_default_boxes() {
    register_taxonomy_for_object_type('post_tag', 'any');
    }
  6. wpcanyon
    Member
    Posted 1 year ago #

    I don't think there's a value for all. And that second parameter (for the post type) is for a single post type.

    Why don't you attach the post_tag taxonomy directly in the register_post_type

    register_post_type( 'post_type_name', array(
        'taxonomies' => array( 'post_tag' ),
        'blah blah' => 'blah blah'
        ...
    ));

Topic Closed

This topic has been closed to new replies.

About this Topic