Hey guys,
I’ve already read so many threads about that topic and I don’t get why my code won’t work. Now I’m more at a point that I messed around that much that I don’t know anything no more.
My setup is quite simple:
In releases there’s a post object named “associated_artist” with a single select fpr picking the right artist.
Of course my goal is to make them relate. I’m working on the single artist page and want to display all releases of the artist. (album name, release date, artwork). This is what I have a the moment:
$args = array(
'post_type' => 'releases_post_type',
'posts_per_page' => -1,
'meta_query' => array(
array(
'key' => 'associated_artist',
//'value' => '"' . get_the_ID() . '"', // won't return anything
//'value' => $artist_name, // the variable for displaying the name in frontend, doesnt work
//'value' => 'Artist name', // won't work either. I'm not sure why
'compare' => 'LIKE'
)
)
);
var_dump(get_the_ID()); // returns different int-ID's for each artist
var_dump($artist_name);
// query
$releases = new WP_Query( $args );
// loop
while( $releases->have_posts() )
{
$releases->the_post();
the_title();
// ...
}?>
If I just leave the ‘value’ in $args blank, it returns all releases of all artists. That’s cool, but not exactly what I want.
Looking forward to some helpful replies. ๐
Best,
Renรฉ
this should work
'meta_query' => array(
array(
'key' => 'associated_artist',
'value' => get_the_ID(),
'compare' => '='
)
)
A post object field that only allows 1 selection does not store an array like a relationship does. It will only store and array if you allow multiple selections. Soe the quotes around the ID and the LIKE comparison is not required.
Thanks a lot! Now I get it.
I made it work before by:$artist_id = get_the_id();
and using the variable instead. Couldn’t see why this should work and using the function itself won’t. ๐
The topic ‘Query for post object’ is closed to new replies.
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.