WordPress.org

Support

Support » Plugins and Hacks » Hacks » [Resolved] Omit orphaned postmeta values from wpdb query

[Resolved] Omit orphaned postmeta values from wpdb query

  • iamshawnrice

    @iamshawnrice

    Hi.

    Please take a look at http://drimproperties.com/property-search-2/

    I am using the following code to generate the bedroom select input:

    <?php
    	$metakey = 'bedrooms';
            $bedrooms = $wpdb->get_col($wpdb->prepare("SELECT DISTINCT meta_value FROM $wpdb->postmeta WHERE meta_key = %s ORDER BY meta_value ASC", $metakey) );
    
    	if ($bedrooms) {
    	foreach ($bedrooms as $bedroom) {
    	$bedStr = str_replace(".","", $bedroom);
    	echo "<option value=\"" . $bedStr . "\">" . $bedroom . "</option>";
    		}
    	}
    ?>

    Many of these metakey values (namely all of the .5’s) are orphaned from deleted/edited posts. As such I would like to omit them from the query.

    Does anyone have insight on how to accomplish this?

    Thanks.

Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘[Resolved] Omit orphaned postmeta values from wpdb query’ is closed to new replies.