desiDesign desiDesign - 1 year ago 85
PHP Question

Wordpress getting updated meta for multiple posts

I am working with wp updating meta values.In my codes here is the main function :

$get_post_ids = array();
$get_post_ids[] = $_REQUEST['ids'];

foreach ($get_post_ids as $post_id) {
$meta_value = get_post_meta( $post_id, 'resturent_featured', true );
if( $meta_value == 'yes' ){
$new_value = update_post_meta( $post_id, 'resturent_featured', 'no' );
$new_value = update_post_meta( $post_id, 'resturent_featured', 'yes' );

Its working when i select one post.but not working when selecting multiple posts.

Answer Source

Something might be wrong here.If you $get_post_ids[] is a array with a key and a value with comma separated then it must be $_REQUEST['ids'] comma separated.Then you have to use this way:

$get_post_ids = $_REQUEST['ids'];
$get_post_ids = explode(',', $get_post_ids);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download