Support

Account

Home Forums Front-end Issues using post ID inside reverse relationship querie

Unread

using post ID inside reverse relationship querie

  • Hello,

    I’m using relationship field on one of my custom post type (releases).

    all my realease have a relationship field with “artists” post, so all my releases are associated with one artist.

    now i’m trying to perform a reverse query to display all the “releases” associated with the artist selected in my relationship field.

    here is my code so far :

    <?php 
    $releases = get_posts(array(
    'post_type' => 'releases',
    'numberposts'=> -1,
    'post__not_in' => array( $post->ID ),
    'meta_query' => array(
    array(
    'key' => 'artist',
    'value' => 191,
    'compare' => 'LIKE'
    )
    )
    ));?>
    <?php if( $releases ): ?>
    <?php foreach( $releases as $release ): ?>
    
    <div class="col-xs-2 text-center">
    
    <a href="<?php echo get_permalink( $release->ID ); ?>" class="related_releases" title="<?php echo get_the_title($release->ID); ?>">
    
    <img src="<?php echo get_the_post_thumbnail_url($release->ID, 'full'); ?>">
    
    </a>
    
    </div>
    
    <?php endforeach; ?>
    
    <?php endif; ?>

    with this code, all the releases from artist ID “191” are displayed on y custom post type.

    the problem is that I’m trying to display the releases from the artist associated with the “release” post.

    what I’m trying to do is to get the ID of the artist inside my querie, like this (width “get_the_ID()” instead of “191”)

    <?php 
    $releases = get_posts(array(
    'post_type' => 'releases',
    'numberposts'=> -1,
    'post__not_in' => array( $post->ID ),
    'meta_query' => array(
    array(
    'key' => 'artist',
    'value' => get_the_ID(),
    'compare' => 'LIKE'
    )
    )
    ));?>

    but I get the ID of the “release” post, not the ID of the artist.

    can anyboby help me with this ?

    hope you understand my issue, sorry for my bad english

Viewing 1 post (of 1 total)

You must be logged in to reply to this topic.