WordPress.org

Ready to get started?Download WordPress

Forums

sql with relationship between wp_post and wp_postmeta (4 posts)

  1. somtam
    Member
    Posted 1 year ago #

    Hello everybody,

    I made a custom post type "events".
    Then in this custom post I made a meta boxe in which I insert a <select> with the id of the custom post type "artists".
    Everything works well, but how can i get the artist name in the archive-events.php?
    If in the loop I do: <?php echo get_post_meta($post->ID, '_artist_id', true);?>
    I get only the ID.

    thanks in advanced!

  2. Maybe I'm missing something, but if you're storing the artist's ID in the meta field, that's what you're going to get back from get_post_meta().

    If that's the case, you could just wrap your get_post_meta() call in get_the_title(), e.g.

    echo get_the_title( get_post_meta( $post->ID, '_artist_id', true ) );
  3. somtam
    Member
    Posted 1 year ago #

    Drew, Yes! you're right!
    and when I'm in the artist page, to let people know at which Events they're going to partecipate I do inside the loop, every cycle, another query like:

    $args = array(
    'post_type'=>'events',
    'meta_key' => '_artist_id',
    'meta_value' => $post->ID,
    );
    $sql = new WP_Query( $args );

    do you think is correct?
    thanks a lot!

  4. That should probably work, yes. And in that case you'll have a full object to work with, not just the ID.

Topic Closed

This topic has been closed to new replies.

About this Topic