• Resolved justbishop

    (@justbishop)


    I’m working on a blog where each entry has an audio file associated with it. The audio file URL for each post (remotely hosted) for each post is entered into a custom field (using the Custom Field Template plugin), and called into a flash player on each post.

    What I’d like to do, in addition to offering each posts audio file on it’s own single.php page, is to offer a week’s worth (or some other number, not sure yet) in a player on the sidebar or header or something. I know where the URLs would need to go in the player code, but I’m not sure how to call the latest 7 results of one custom field. The results would also need to print separated by a pipe, which I’m sure goes in the call somewhere, right?

    Thanks in advance, and please let me know if more info or explanation is needed!

Viewing 6 replies - 1 through 6 (of 6 total)
  • This also displays the post title but you can fix this to do what you want:

    <?php
    $custom_key = 'video';
    $args=array(
      'meta_key'=> $custom_key,
      'post_type' => 'post',
      'post_status' => 'publish',
      'posts_per_page' => 7,
      'caller_get_posts'=> 1
    );
    $my_query = null;
    $my_query = new WP_Query($args);
    if( $my_query->have_posts() ) {
      while ($my_query->have_posts()) : $my_query->the_post(); ?>
        <p><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></p>
        <?php
        $link = get_post_meta($post->ID, $custom_key, true);
        if ($link){
          echo 'link: '.$link ;
        }
      endwhile;
    }
    wp_reset_query();  // Restore global post data stomped by the_post().
    ?>
    Thread Starter justbishop

    (@justbishop)

    Thanks for the reply, but I’m super confused by that. All I need is something to output the text:

    custom field value|custom field value|custom field value|custom field value

    etc.

    It will go into a piece of code for a flash mp3 player somewhere outside of the loop, I’m not sure where I want to put it yet. At the moment, to output just one value from the custom field in question, I have the following in the player code:

    <?php $values = get_post_custom_values("mp3"); echo $values[0]; ?>

    …I’m super confused by that

    Oops, here’s what that does.

    Get ‘latest’ seven posts that have the ‘video’ custom field, then display the post title and the value that is in that custom field.

    Of course you need to change the $custom_key = ‘video’; to be your custom field, and you would delete the display of the title and the custom field (which I left for examples sake).

    Thread Starter justbishop

    (@justbishop)

    If all of that (minus the title stuff) needs to go into the spot where my one little line of code is now, then I don’t think I need the feature that badly. Thanks for the help, though ??

    La respuesta de MichaelH no tiene nada que ver con la pregunta. La respuesta de MichaelH, como él mismo dice es, para mostrar post con un determinado custom_field, pero la pregunta no era esa (tampoco era tan difícil entenderla), la pregunta es como mostrar resultados múltiples de un solo custom_field.

    por ejemplo, los resultados obtenidos por un checkbox en un custom_field.

    Yo tengo la misma duda, y aún no he encontrado una solución.

    Solution to the problem:

    <?php
    $Field_Key = get_post_meta($post_id, 'Field_Key', false);
    foreach ($Field_Key as $anything) {echo "<li>".$anything."</li>";}echo "</ul>";
     ?>
Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Return Multiple Results From One Custom Field’ is closed to new replies.