Associate Press Release custom post type to Artists Custom Post type
https://www.advancedcustomfields.com/resources/relationship/
- create artists custom post type
- create pressrelease custom post type
- create a custom field for artists called: press_releases
- When you create press releases name the titles according to the relationship with
the artist, ie: press release for ichigo
- then in Artists custom post type you will see a field of press releases, this enables
you to select a post of this press release type and associate with this artist, like
displaying an excerpt below the content of this artist with a link to
/pressrelease/nameofpressrelease
1) artists custom post type:
get_header(); ?>
<!-- SINGLE-ARTISTS.PHP -->
<div class="col-md-12">
<div class="col-md-4">
<div class="artist_name">
<?php the_field('name') ; ?>
</div>
<div class="artist_series">
<?php the_field('artist_number') ; ?>
</div>
<div class="artist_series_sub">
<?php the_field('series') ; ?>
</div>
<div class="artist_details">
<?php the_field('details') ; ?>
</div>
<div class="artist_description">
<?php the_field('description') ; ?>
</div>
</div>
<div class="col-md-8">
<img src="<?php the_field('image') ?>">
</div>
</div>
<div class="col-md-12 press_cont">
// NOTE HERE BEGINS the 'relationship' field called: press_releases
<div class="press_release">PRESS RELEASE:</div>
<?php
// get press release relationship and associate with this artist:
$posts = get_field('press_releases');
if( $posts ): ?>
<?php foreach( $posts as $post): // variable must be called $post (IMPORTANT) ?>
<?php setup_postdata($post); ?>
<div class="press_excerpt"><?php the_excerpt() ; ?></div>
<a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
<?php endforeach; ?>
<?php wp_reset_postdata(); // IMPORTANT - reset the $post object so the rest of the page works correctly ?>
<?php endif; ?>
</div>
<?php get_footer(); ?>
2) craete archive-pressrelease.php
<?php get_header(); ?>
<!-- ARCHIVE-PRESS RELEASES.PHP -->
<div class="content-padder">
<?php //
$artist_press = new WP_Query(array('post_type' => 'pressrelease' ) );
while ($artist_press->have_posts()) : $artist_press->the_post();
get_template_part( 'content', 'press-releases' );
endwhile;
?>
</div><!-- .content-padder -->
<?php get_footer(); ?>
3) content-pressrelease.php:
<div class="news_cont">
<div class="col-md-6">
<h4 class="page-title"><a href="<?php the_permalink(); ?>" rel="bookmark"><?php the_title(); ?></a></h4>
<div class="exibition_date"><?php the_time('F jS, Y') ?></div>
<?php the_excerpt(); ?>
<?php the_field('name'); ?>
<div class="news_readmore"><a href="<?php the_permalink(); ?>">View</a></div>
</div>
<div class="col-md-6">
<?php the_post_thumbnail(); ?>
</div>
</div>
4) Now single-pressrelease.php, this displays the individual press releases posts
get_header(); ?>
<!-- SINGLE-PRESS-RELEASES.PHP -->
<div class="col-md-12">
<?php while ( have_posts() ) : the_post(); ?>
<?php get_template_part( 'content', 'single' ); ?>
<?php _tk_content_nav( 'nav-below' ); ?>
<?php endwhile; // end of the loop. ?>
</div>
<?php get_footer(); ?>
5) content-single.php will contain something like:
<header>
<h1 class="page-title"><?php the_title(); ?></h1>
<div class="entry-meta">
<?php _tk_posted_on(); ?>
</div><!-- .entry-meta -->
</header><!-- .entry-header -->
<div class="entry-content">
<div class="entry-content-thumbnail singlepost">
<?php the_post_thumbnail(); ?>
</div>
<?php the_content(); ?>
<?php
wp_link_pages( array(
'before' => '<div class="page-links">' . __( 'Pages:', '_tk' ),
'after' => '</div>',
) );
?>
</div><!-- .entry-content -->