• Resolved sdawson26

    (@sdawson26)


    I’ve got a loop that works, so I’ll just include the important parts. The question I have is more about PHP than WP, but hopefully someone has dealt with this before.

    Basically what I’m trying to do is create an agenda page for a conference website. I’ve got a loop of agenda events, and each post has a custom field of ID values for speakers that will be speaking at each of those events. So i’ve got an event with an advanced custom field that has a value of ‘1027,965,963’. Hopefully this explains my question.

    Why is it that THIS WORKS….

    $post_list = array(1027,965,963);
    foreach( $post_list as $post_id ) : query_posts('p=' .$post_id . '&posts_per_page=-1');
    while (have_posts()) : the_post();

    But THIS only returns info on 1027 and stops there?

    $speakers = '1027,965,963';
    $post_list = array($speakers);
    foreach( $post_list as $post_id ) : query_posts('p=' .$post_id . '&posts_per_page=-1');
    while (have_posts()) : the_post();

    How can i put these comma separated ID’s into the array from a separate variable? Does it have something to do with being a string, and needing to convert it to something else? If so, what? Thanks for any help you can offer!

Viewing 1 replies (of 1 total)
  • Thread Starter sdawson26

    (@sdawson26)

    It was explode all along… I was able to successfully call a loop from inside a loop using the ACF field “speakers”. It was a comma separated value of all of the speakers assigned to the parent.

    if(get_field('speakers')) {
    $speakers = get_field('speakers');
    $speakers = explode(',',$speakers);
    foreach($speakers as &$postdata){
    query_posts('p=' . $postdata . '&posts_per_page=-1');
    while (have_posts()) : the_post();
    }
Viewing 1 replies (of 1 total)
  • The topic ‘Trying to put a variable inside of an array’ is closed to new replies.