Hmmm, not having any luck. There’s definitely something in there. However the data that’s still being displayed is coming from the latest artist and not the one that appears in the URL.
Is there a way of querying what data is displayed based on the artist post slug ? (site.com/artists/jack/works)
Sorry i’m completely stumped with this and everything I try just isn’t working.
Sorry, i’m not sure I follow?
The name of the file is archive-artists.php
Sorry for the late reply:
When I put this code in my archive page for artists, it only outputs the field data for the latest post in that custom post type, rather than the one in the url.
Eg: Three artists in order:
Joe
James
Jack
If I’m on site.com/artists/jack it out puts the data for Joe.
<div class="container-fluid">
<?php // check if entries exists
if( have_posts() ):
// loop start
while( have_posts() ): the_post(); ?>
<?php
$posts = get_field('featured_works');
if( $posts ): ?>
<ul>
<?php foreach( $posts as $p ): // variable must NOT be called $post (IMPORTANT) ?>
<li>
<a href="<?php echo get_permalink( $p->ID ); ?>"><?php echo get_the_title( $p->ID ); ?></a>
<span>Custom field from $post: <?php echo $post->post_name; ?></span>
</li>
<?php endforeach; ?>
</ul>
<?php endif; ?>
<?php endwhile;
// reset query
wp_reset_postdata();
// end
endif; ?></div>
Thanks @pixelbart – that worked in rewriting my urls. My next question would be around what I would label my template. With your change it’s now loading my Artists landing page when i goto site.com/artists/joe/works.
Also is there a special query I would need on that page to pull the content through ?
Apologies for posting in the wrong forum, I wasn’t sure which to put it in.
Thanks again for your help!
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.