Wordpress displaying custom post types and their fields

lowercase picture lowercase · Jun 27, 2012 · Viewed 23.4k times · Source

I have set up a Custom Post Type called 'RELEASES' - think music cd release.

This post type has fields named 'release_artist', 'release_title', 'release_date', 'release_artwork' and 'release_tracklisting' for entering all of the relevant music cd information.

I am having real trouble actually displaying this information in my Wordpress template. I have really only had luck outputting a list of the titles and none of the other data.

Any idea what I put in the LOOP to display all of the information? Preferably each in its own LIST item so I can style each separately?

Any thoughts greatly appreciated.

Answer

Tomek Buszewski picture Tomek Buszewski · Jun 27, 2012

Are those custom fields? If yes, try what codex.wordpress.org is saying. Better yet, try ACF plugin.

-- edit

If you want to display parts of your pages on other ones (eg. on your home), you need to use query_posts. This is fairly simple function. For your loop, try something like this:

      <?php
        global $wp_query;
        query_posts(array(
            'post_type' => 'releases'
        ));
        while(have_posts()) : the_post(); ?>
            <?php $key = get_post_meta($post->ID, 'Opis nazwy'); ?>
            <li <?php post_class(); ?>><a href="<?php the_permalink(); ?>"><?php if($key) { echo $key[0]; } else { the_title(); }; ?></a></li>
            <?php
        endwhile;
        wp_reset_query();
        ?>

$key is a single value, here set to release_artists. It's purely for testing. If it works - feel free to define your own variables.