• Quick question about Custom Post Types:

    To get the label of a post, i use:

    <?php
        $post_type = get_post_type_object( get_post_type($post) );
        echo $post_type->label;
    ?>

    But is it possible to get that label as a link to all posts posted under that label? (did that sentence make sense?)

    To give an example what I’m looking for. I got a Custom Post Type named news-entry and label News. On the start page i only show the 5 recent posts of that Custom Post Type. And I want to implement a link, that shows all posts under that current Custom Post type:

    Figure the output would be:
    <a href="link-to-all-posts-under-this-label">Show all posts from <?php echo $post_type->label; ?></a>

    Am I thinking about this the right way?

Viewing 4 replies - 1 through 4 (of 4 total)
  • $term = get_term_by( ‘slug’, get_query_var( ‘term’ ), get_query_var( ‘taxonomy’ ) );
    
    $obj = get_terms($term->texonomy,'hide_empty=0');
    
    echo $obj->label;

    Try this once. But I am not tested it.

    Thread Starter hixen

    (@hixen)

    Thank you chinmoy29, been trying to get your code to work but gets nothing out from it.

    I’m no code expert, care to tell me what this code does?

    tried it as:

    <?php
    	$term = get_term_by( 'slug', get_query_var( 'term' ), get_query_var( 'taxonomy' ) );
    	$obj = get_terms($term->texonomy,'hide_empty=0');
    	echo $obj->label;
    ?>
    Thread Starter hixen

    (@hixen)

    Still haven’t figured this one out ??

    Anyone know a way to get all posts from a Custom Post Type.

    I know how to get all posts from a category, i know how to get all posts from an taxonomy, but how do I get them from a Custom Post Type.

    Assume your custom post type is movies. So function would be
    query_posts('post_type=movies');

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Show all posts from current Label using Custom Post Types’ is closed to new replies.