I’ve an actual property web site. On property pages customers can save houses as a favourite. The property will get added to the person meta knowledge. I can efficiently add and delete entries from the only property web page with no points.
I’ve “view favorites” web page that shows all saved houses. I might like customers to have the ability to take away saved houses from this web page. My points is the houses are being displayed in a foreach and when you select to take away one dwelling…all houses find yourself being eliminated. I am certain my concern is that the foreach is looping the delete_user_meta operate however I can not work out methods to set it up appropriately.
Every property has an array of entries (mattress / tub / worth / and so forth). I am assuming I have to POST the array and use the posted array within the delete operate however I can not determine it out.
My code:
<?php
$user_id = get_current_user_id(); //Get present person ID
international $current_user; wp_get_current_user();
$user_id = $current_user->ID;
$meta = get_user_meta($user_id, 'savedhome');
?>
<div class="row"> <!--defines and shows every outcome successfully-->
<?php foreach ($meta as $key => $worth) { ?>
<?php
foreach($worth as $k1 => $v1) {
if ($k1 == 'Beds'){
$k1beds = $v1;
}// finish if beds
if ($k1 == 'Baths'){
$k1bath = $v1;
}// finish if baths
if ($k1 == 'Value'){
$k1price = $v1;
}// finish if Value
}//finish foreach worth as k1 v1
?>
<div class="favprice">
<?php echo "$$k1price";?>
</div>
<div class="favbed">
<?php echo "$k1beds";?>
</div>
<div class="favbath">
<?php echo "$k1bath";?>
</div>
</div><!-- shut row -->
<?php
echo '<pre>' , var_dump($worth) , '</pre>'; //shows appropriate array for every dwelling
if(isset($_POST["Remove"])){
delete_user_meta($user_id, 'pluginlink', $worth);
}//finish if
//Under will decide if dwelling exists in person meta and show the proper save/delete button
$meta = get_user_meta($user_id, 'savedhome');
if(array_search($k1price, array_column($meta, 'Value')) !== false) {
$savebutton = "show: none;";
$deletebutton = "show: block;";
}
else {
$savebutton = "show: block;";
$deletebutton = "show: none;";
}
?>
<div class="buttondisplay" fashion=" <?php echo $savebutton; ?> ">
<type methodology="publish" enctype="multipart/form-data">
<button kind="submit" identify="submit" fashion="background-color: #fff; padding-left:3px;" ><i class="fa fa-heart-o" aria-hidden="true" ></i></button>
</type>
</div><!-- finish save button -->
<div class="deletebutton" fashion=" <?php echo $deletebutton; ?> ">
<type methodology="publish" enctype="multipart/form-data" >
<button kind="submit" identify="Take away" worth="<?php echo $k1mlsid; ?>" fashion="background-color: #fff; padding-left:3px;"><i class="fa fa-heart" aria-hidden="true" ><?php echo $loginouttext; ?></i></button>
</type>
</div><!-- finish delete button -->
<?php } //finish foreach meta as key worth
?>