pass an array as key in a wordpress function as for example get_post_meta -
this simple get_post_meta function:
<?php $key_1_values = get_post_meta( 76, 'key_1' ); ?>
its homecoming value of key 'key_1'.
but if want values of multiple keys, 'key_1', 'key_2', etc..), possible pass array key or utilize special chars ?
for example:
<?php $key_1_values = get_post_meta( 76, array('key_1','key_2','key_3') ); ?>
and possibile values of keys starts string ?
for example:
<?php $key_1_values = get_post_meta( 76, 'key_%' ); ?>
thanks.
according to documentation not possible, key has string.
but can wrap in own function:
// getting multiple meta values function get_post_meta_array($post, $keys) { $return = array(); foreach ($keys $key) { $return[$key] = get_post_meta($post, $key); } homecoming $return; }
to values prefix can utilize get_post_custom()
fetch fields of post, filter through keys.
wordpress
No comments:
Post a Comment