I have the follow problem. I have an old website (before WordPress taxonomy) with some posts (companies). Companies are posts with metakey "field-company-type" and metavalue = "j".
Each company can exists as distinct posts (same title, but different content) in multiple categories (so I can have a post called Microsoft in software section and again another post called also Microsoft (same title, but different content) in hardware section.
I want to display a list with all companies (but no double entries). So only one Microsoft in my example.
My below code - still display duplicates
<?php
if ($companies = $wpdb->get_results("SELECT DISTINCT wposts.*
FROM $wpdb->posts wposts, $wpdb->postmeta wpostmeta
WHERE wposts.ID = wpostmeta.post_id
AND wpostmeta.meta_key = 'field-company-type'
AND wpostmeta.meta_value = 'j'
AND wposts.post_status = 'publish'
AND wposts.post_type = 'post'
AND wposts.post_date < NOW()
ORDER BY wposts.post_title DESC")):
?>
<ul>
<?php
foreach ($companies as $post) {
if ($post->post_title == '') $post->post_title = sprintf(__('Post #%s'), $post->ID);
echo "<li><a href='".get_permalink($post->ID)."'>";
the_title();
echo '</a></li>';
}
?>
</ul>
<?php endif; ?>
Can anybody help me with this?