WordPress.org

Ready to get started?Download WordPress

Forums

CPT-onomies: Using Custom Post Types as Taxonomies
get_posts - get posts based on the current page (2 posts)

  1. KevvR
    Member
    Posted 7 months ago #

    Hey,

    First of all: thanks a million for the great plugin. It has proven to be a great support for out new project.

    Now, I am a complete PHP-noob and coding in a theme for the first time. So this might be something really stupid, but I still hope someone can help me. I am working on a videogames website in which we are building a videogame database. Ever game will have a separate archive-page and we want to show an overview of all the articles that have a custom post type Game connected to it. Now I've used the code from your website like this:

    <?php $post = get_posts( array(
       'numberposts' => -1, // we want to retrieve all of the posts
       'post_type' => 'post',
       'games' => 'battlefield-4',
       'suppress_filters' => false // this argument is required for CPT-onomies
    ) );
    
    if( $post ) {
       ?><ul><?php
          foreach ( $post as $artikel ) {
             ?><li><a href="<?php echo get_permalink( $artikel->ID ) ?>" title="<?php echo get_the_title( $artikel->ID ); ?>"><?php echo get_the_title( $artikel->ID ); ?></a></li><?php
          }
       ?></ul><?php
    } ?>

    This works. But now I want to build it that it automatically replaces Battlefield-4 with the archive page it is on. What do I need to place here to make this happen?

    Any help would be great!

    Greets,

    Kevin

    http://wordpress.org/plugins/cpt-onomies/

  2. Rachel Carden
    Member
    Plugin Author

    Posted 7 months ago #

    I'd give get_query_var( 'post_type' ) a try.

Reply

You must log in to post.

About this Plugin

About this Topic