Skip to content

Instantly share code, notes, and snippets.

@kundancool
Created December 2, 2016 11:38
Show Gist options
  • Save kundancool/f73b6848b03bf6ded5f97c5947c54d75 to your computer and use it in GitHub Desktop.
Save kundancool/f73b6848b03bf6ded5f97c5947c54d75 to your computer and use it in GitHub Desktop.
Get WCK select options by slug
<?php
function get_wck_select_by_slug($slug) {
global $wpdb;
$results = $wpdb->get_results( "select * from $wpdb->postmeta where meta_value = '".$slug."'", ARRAY_A );
$post_id = $results[0]['post_id'];
$separator = explode('_', $results[0]['meta_key']);
$suffix = isset($separator[1]) ? '_'.$separator[1] : '';
$options = explode(',', get_post_meta($post_id, 'options'.$suffix, true));
$labels = explode(',', get_post_meta($post_id, 'labels'.$suffix, true));
/* initialize var */
$return_var = array();
/* create array for select */
foreach ($options as $key => $value) {
$return_var[$value] = $labels[$key];
}
return $return_var;
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment