• Resolved ivyowl

    (@ivyowl)


    I want to show a list of posts from a Custom post type “Artists”.

    I want to list them by their post ID.

    I want to show them on a at the end of the custom posts type “Events” posts.

    The list of post ID’s will come from a custom Meta field in the “Events” post the key being $event_artists. (the field being a list of numbers separated by comma’s.

    I can get it show posts from the blog so far no luck listing any “Artist” posts.

    I think a custom query would be best. But i just don’t understand them that well.

    I’ve tried using get_posts with no luck as of yet.

    Any help would be much appreciated.

    Thanks in advance,

    Jonny

Viewing 6 replies - 1 through 6 (of 6 total)
  • This loop should work for you

    $artist_posts_array = explode(',', $artist_custom_field);
    $loop = new WP_Query( 'posts__in' => $artist_posts_array);
    forwhile( $loop->have_posts() ) : $loop->the_post();
       // do whatever you need to do the post here
    endwhile;

    Thread Starter ivyowl

    (@ivyowl)

    Thanks transom,

    i’ve actually almost cracked it (i think!)

    This the code gives is close to what i want.

    the problems are.

    1. it only works if i use a specified post id, in this case 153.
    ($post->ID gives me nothing)

    2. although the echo $event_artists_list gives me: 167, 168 (which is the value of event_artists for post 153) it only lists 167 and not 168.

    appart from that it works perfectly.

    many thanks again.

    [Code moderated as per the Forum Rules. Please use the pastebin]

    Thread Starter ivyowl

    (@ivyowl)

    btw: the echo $event_artists_list is there just to test what i’m being returned.

    The problem is that we are mixing two loops and $post can only support one of them.
    Unless you post your code using Pastebin, I can’t tell how you are using the structure.

    I recommend save the value of the $post variable (you’ll have to declare it a global) before entering the $loop. You can’t use any of the template tags to refer to the containing post – just the inner post.

    Thread Starter ivyowl

    (@ivyowl)

    The problem is that you didn’t use the explode statement above to split the string into a PHP array.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Listing specific Custom Posts by ID – wp_query?’ is closed to new replies.