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:
- custom post type: releases
- custom post type: artists
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รฉ