Created
December 2, 2016 11:38
-
-
Save kundancool/f73b6848b03bf6ded5f97c5947c54d75 to your computer and use it in GitHub Desktop.
Get WCK select options by slug
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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