I created a Custom Field ('custom_name') to allow content editors to specify a 'custom_name' (different from the title of the page) to any post created:
- custom_name - (Field type --> 'text')
For a specific page I created 4 Custom Fields that lets the content editor pick 4 articles he would like to feature:
- featured_content_1 (Field type --> 'Post Object')
- featured_content_2
- featured_content_3
- featured_content_4
- promoted
On that page I display the featured content as a list of thumbnails:
<?php
for ($i=1; $i<=4; $i++) {
$fieldName = 'featured_content_' . $i;
$featuredContentPostID = get_field($fieldName)->ID;
$selectedFeaturedContent = get_post( $featuredContentPostID );
$promoted_content = get_field('promoted');
?>
<li class="<?php if($promoted_content == $fieldName) { echo 'active'; }?>">
<a href="<?php echo esc_url( get_permalink($featuredContentPostID) ); ?>">
<?php echo get_the_post_thumbnail( $featuredContentPostID, 'thumbnail' ); ?>
<span><?php echo $selectedFeaturedContent->post_title ?></span>
</a>
</li>
<?php
}
?>
I manage to query and display the 'artist_name' in a different loop:
<?php
$artistNameArgs = array(
'meta_key' => 'artist_name'
);
$artistName = new WP_Query( $artistNameArgs );
?>
<ul>
<?php if( $artistName->have_posts() ): ?>
<?php while ( $artistName->have_posts() ) : $artistName->the_post(); ?>
<li><?php the_field('artist_name'); ?></li>
<?php endwhile; ?>
<?php wp_reset_postdata(); ?>
<?php endif; ?>
</ul>
How can I combine the two so the 'artist_name' appears in the LI of the thumbnails LIs ?
Thanks
UPDATE
I managed to make it work. Here is my updated code:
<?php
for ($i=1; $i<=4; $i++) {
$fieldName = 'featured_content_' . $i;
$featuredContents = get_field($fieldName);
$featuredContentPostID = get_field($fieldName)->ID;
$selectedFeaturedContent = get_post( $featuredContentPostID );
$promoted_content = get_field('promoted');
?>
<li class="<?php if($promoted_content == $fieldName) { echo 'active'; }?>">
<a href="<?php echo esc_url( get_permalink($featuredContentPostID) ); ?>">
<?php echo get_the_post_thumbnail( $featuredContentPostID, 'thumbnail' ); ?>
<span>
<?php
foreach($featuredContents as $featuredContent){
the_field('content_name', $featuredContent);
}
?>
</span>
</a>
</li>
<?php
}
?>