WordPress.org

Forums

Show all posts from current Label using Custom Post Types (5 posts)

  1. hixen
    Member
    Posted 5 years ago #

    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?

  2. chinmoy29
    Member
    Posted 5 years ago #

    $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.

  3. hixen
    Member
    Posted 5 years ago #

    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;
    ?>
  4. hixen
    Member
    Posted 5 years ago #

    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.

  5. chinmoy29
    Member
    Posted 5 years ago #

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

Topic Closed

This topic has been closed to new replies.

About this Topic