php - Wordpress - get meta data only from "published" articles -
i have dropdown meta data posts:
<form name="search" action="" method="get" class="form-dropdown"> <select name="city"> <option>stadt wählen</option> <?php $metakey = 'city'; $counties = $wpdb->query( $wpdb->prepare( " select distinct meta_value $wpdb->postmeta pm join $wpdb->post p on pm.post_id = p.id meta_key = %s , post_status = 'published' order meta_value asc ", $metakey ) ); if ($counties) { foreach ($counties $city) { echo "<option value=\"" . $city . "\">" . $city . "</option>"; } } ?> </select> <input type="submit" value="anzeigen" /> </form>
but
and post_status = published
seems wrong here. idea how show meta data published posts? posts per rss feed plugin "feedwordpress" , puts old posts post status "retired" shown. no found no option in plugin put them trash instead ...
you missing single quotes in query, published
string value , not column. ah, , @khushboo mentioned, post_status
indeed column of posts table. have this:
$wpdb->query( $wpdb->prepare( " select distinct meta_value $wpdb->postmeta pm join $wpdb->post p on pm.post_id = p.id meta_key = %s , post_status = 'publish' order meta_value asc ", $metakey ) );
but why don't use other query functions query_posts , query params?
Comments
Post a Comment