The function below lists the values ââof a custom field in the order they are posted. example:
- Frank Capra
- Alfred Hitchcock
- Woody Allen
- Woody Allen
- Frank Capra
- Pedro Almodóvar
I’d like to get this list in alphabetical order and without repetition, with a link to each item <a href="Woody-Allen">Woody Allen</a>
. example:
- Alfred Hitchcock
- Frank Capra
- Pedro Almodóvar
- Woody Allen
This is the code:
<?php
$movie_reviews = get_posts( 'numberposts=-1&orderby=post_name' );
foreach( $movie_reviews as $post ) : setup_postdata( $post );
?>
<span>
<?php $director = get_post_meta( $post->ID, "director", $single = true );
if( $director !== '' ) {
echo $director;
} ?>
</span>
<?php endforeach; ?>
Is this possible?
Using
get_posts
, you can order posts withmeta_value
like this :To remove duplicates, you can build an array of directors :
And after you can display them as you want :
EDIT : To display only a* directors :