WordPress.org

Ready to get started?Download WordPress

Forums

Delete custom field (2 posts)

  1. cip6791
    Member
    Posted 2 years ago #

    Hi,

    I have multiple custom fields named Awards in the following format http://somelink.com/image.jpg&http://somelink.com. I use the below code to create a little gallery. I would like to use the <span class='delete'><a href=".'#'." title='Delete!' />[x]</span> to delete each individual image. I m not sure how to do this. Can anybody help?

    <?php $awds = get_post_meta($post->ID, "Awards", false); ?>
    
    			<?php foreach($awds as $awd) {
    
    				  $tawd = explode("&", "$awd");
    				  $tawdd = $tawd[0];
    				  $tawddd = $tawd[1];
    
    				  echo '<a href="'.$tawdd.'">'.'<img width="200" src="'.$tawddd.'" alt="alt"/>'.'</a>';
    				  echo "<span class='delete'><a href=".'#'." title='Delete!' />[x]</span>";
    			?>
    
    		<?php } ?>
  2. cip6791
    Member
    Posted 2 years ago #

    I created a new page

    <?php
    /*
    Template Name: Delimg
    */
    ?>
    
    <?php
    
    if($_GET['id'] != ""){
    
    $img = $_GET['id'];
    
    echo $img;
    
    delete_post_meta(?, 'Awards', '?');
    
    }  
    
    ?>

    and modified the delete link.

    echo "<span class='delete'>" . "<a href='http://mysite.com/delimg?id=".$tawdd."'>[x]</a>" . "</span>";

    But I'm still not sure how to get the right custom field.

Topic Closed

This topic has been closed to new replies.

About this Topic