How to query wp_postmeta table for any specific meta_value?
-
I am using following code in the theme files to get some output from the DB:
<?php $querystr = "SELECT DISTINCT meta_value FROM $wpdb->wp_postmeta WHERE 'meta_key' LIKE 'movie_name' ORDER BY meta_value ASC"; $movie_names = $wpdb->get_results($querystr, OBJECT); echo sizeof($movie_names); ?> <ul> <?php foreach ( $movie_names as $movie_name ){ ?> <li><?php echo $movie_name->meta_value; ?> </li> <?php } ?> </ul>
Above code’s result is “0” at the frontend. But when I am running the same query i.e.
SELECT DISTINCT meta_value FROM wp_postmeta WHERE 'meta_key' LIKE 'movie_name' ORDER BY meta_value ASC
in DB then it’s returning 6 rows. Please help me in finding the problem in the code.
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
- The topic ‘How to query wp_postmeta table for any specific meta_value?’ is closed to new replies.