0

My page should display all filmmakers, that have been tagged as "filmmaker" in my posts. I do have posts that feature more than one filmmaker (meta_key = filmmaker) in custom fields, but only the first one appears in the "overview" that I want to display. The other two seem to be ignored. What do I do wrong? (or my predecessor, because I took over this page). Thanks a million.

This is my Code (image of post attached)

<table class="films">
<?php

$letter = '';

foreach($wpdb->get_col("SELECT DISTINCT meta_value FROM $wpdb->postmeta WHERE meta_key = 'filmmaker' ORDER BY meta_value") as $name):
    $title = cnext_letterheading($name);
    if($title && ($title != $letter)) {
        $letter = $title;
        echo '<tr><td><h3>', $letter, '</h3></td></tr>';
    }
?>

<tr class="post film film-line">
    <td class="title">
        <a href="<?php echo get_site_url(); ?>/?filmmaker=<?= urlencode($name) ?>">
            <h2 class="entry-title"><?= htmlspecialchars($name) ?></h2>
        </a>
    </td>
</tr><!-- #post-## -->


<?php endforeach ?>
</table>

enter image description here

3
  • 1
    have you considered using a custom taxonomy instead for these? Querying the post meta table via its values is very expensive, post meta tables are optimised for when you have a known post ID, they're poor at searches/filtering which is what taxonomies are for
    – Tom J Nowell
    Commented Oct 3, 2022 at 12:14
  • It's unclear why a WP_Query isn't being used here...
    – vancoder
    Commented Oct 3, 2022 at 15:42
  • I agree, thank you.
    – Mich___
    Commented Dec 23, 2022 at 11:13

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.