Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.
 <?php 
    $custom_post_types = get_post_types( 
        array(
            '_builtin' => false,
            'public' => true
        ),
        'objects'
     );

    foreach ( $custom_post_types as $custom_post_type ) {
        $custom_post_type->permalink = get_post_type_archive_link( $custom_post_type->label );
    }

    echo '<ul>';
    foreach ( $custom_post_types as $custom_post_type ) {
        echo '<li>';
        echo '<a href="' . $custom_post_type->permalink . '">' . $custom_post_type->label . '</a>';
        echo '</li>';
    }
    echo '</ul>';
    ?>

I want to exclude products and sales CPT from the list. Can anyone help please? Also I want to display the list in ACS order.

share|improve this question
add comment

1 Answer

up vote 2 down vote accepted
<?php
    $custom_post_types = get_post_types( 
        array(
                '_builtin' => false,
                'public' => true
            ),
            'objects'
        );

        ksort( $custom_post_types, SORT_ASC );

        echo '<ul>';

        foreach ( $custom_post_types as $custom_post_type ) {

            $exclude = array( 'products', 'sales' );

            if( TRUE === in_array( $custom_post_type->name, $exclude ) )
                continue;

            $custom_post_type->permalink = get_post_type_archive_link( $custom_post_type->name );

            echo '<li>';
            echo '<a href="' . $custom_post_type->permalink . '">' . $custom_post_type->label . '</a>';
            echo '</li>';

        }

        echo '</ul>';
share|improve this answer
    
The ASC and exclude all working fine but the links doesnt work anymore :( –  mandy Nov 23 '12 at 13:20
    
@mandy At get_post_type_archive_link() use $custom_post_type->name instead of $custom_post_type->label. This works for me. –  Ralf912 Nov 24 '12 at 20:42
    
hi thank you sooooo much :) all working fine now :) –  mandy Nov 26 '12 at 9:52
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.