• I am building a theme to showcase videos that are on a season and episode basis.
    I have custom fields for:
    – title
    – season
    – episode

    How can I make a list in the side bar of links to the other posts that match the current post’s title and season?

    Thanks.

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

    (@findes)

    Here is what I have so far, but there is something wrong with my query…

    <?php
    echo("<ul>");
    $ID = get_the_ID();
    echo("<li>ID = " . $ID . "</li>");
    
    $title = get_post_custom_values('Title', $ID);
    $season = get_post_custom_values('Season', $ID);
    
    echo("<li>Title = " . $title[0] . "</li>");
    echo("<li>Season = " . $season[0] . "</li>");
    echo("</ul>");
    
     $querystr = "
        SELECT wposts.*
        FROM $wpdb->posts wposts, $wpdb->postmeta wpostmeta
        WHERE wposts.ID = wpostmeta.post_id
        AND wpostmeta.meta_key = $title[0]
        AND wpostmeta.meta_key = $season[0]
        AND wposts.post_status = 'publish'
        AND wposts.post_type = 'post'
        ORDER BY wposts.post_date DESC
     ";
    
     $pageposts = $wpdb->get_results($querystr, OBJECT);
    
     ?>
    
    <ul>
    <?php if ($pageposts): ?>
    <?php foreach ($pageposts as $post): ?>
    <?php setup_postdata($post); ?>
    <li><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>">
        <?php the_title(); ?></a></li>
    <?php endforeach; ?>
    <?php else : ?>
    <li>Sorry no other episodes this season, yet.</li>
    <?php endif; ?>
    </ul>
Viewing 1 replies (of 1 total)

The topic ‘list posts in sidebar with matching custom fields’ is closed to new replies.