Support

Account

Home Forums Backend Issues (wp-admin) Display custom field value on edit page Reply To: Display custom field value on edit page

  • Ok, so I have plugin installed and tested with simple echo php, renders fine on edit page.

    screen

    Replaced that with the following code, and clicked update. It doesn’t save php and changes the enhanced field into an empty plain text field.

    The following code breaks the enhanced msg field and makes it revert to a simple text field because of the multiple open / closing php tags.

    
    <?php 
      
      // change the field type to the type
      // of field you want this run on
      // use priority of 1 for before field
      // use priority of 20 for before field  
      add_action('acf/render_field/type=url', 'field_name_render_url_image', 20, 1);
      // change the function name to something unique
      function field_name_render_url_image($field) {
         // change $field name to 
         // the field to add the image to 
        $field_name = 'video_poster_text';
        if ($field['_name'] != $field_name) {
          // not our field
          return;
        }
        // uncomment this if you want to see value of $field
        //echo '<pre>'; print_r($field); echo '</pre>';
        // get the post id
        global $post;
        $post_id = $post->ID;
        // get the current value of the field
        // using get_post_meta to avoid confilcts
        $url = get_post_meta($post_id, $field_name, true);
        if (!$url) {
          // nothing has been entered
          ?><p>Enter a URL and Update to View.</p><?php 
          return;
        }
        // make sure the url is an image
        // alter regex to change allowed image extensions
        if (!preg_match('/\.(jpg|jpeg|png|gif)$/i', $url)) {
          // not an image we want to allow
          ?><p>The Entered is Not A Valid Image URL. Enter a Valid Image URL and Update to View.</p><?php 
          return;
        }
        // if we get here then show the image
        ?>
          <img src="<?php echo $url; ?>" />
        <?php 
      } // end function field_name_render_url_image
      
    ?>