I’ve been trying to add a field to Quick Edit. Somehow it works: it is displayed and if you enter a value in the input field, the value is saved into a custom field. However, can’t seem to find a way to retrieve the value of the custom field. Here’s what I got so far:
add_action('quick_edit_custom_box', 'ilc_quickedit_show', 10, 2);
function ilc_quickedit_show( $col, $type ) {
if( $type != 'event' ) return; ?>
<fieldset class="inline-edit-col-left">
<div class="inline-edit-col">
<div class="inline-edit-group">
<label for="eventdate" style="font: italic 12px Georgia, serif;">Event Date</label>
<span class="input-text-wrap">
<input type="text" name="eventdate" id="eventdate" size="10" value="">
</span>
</div>
</div>
</fieldset>
<?php
}
entered values are saved using:
add_action('save_post','ilc_quickedit_save',10,3);
function ilc_quickedit_save($post_id, $post) {
if( $post->post_type != 'event' ) return;
update_post_meta($post_id, 'Event Date', $_POST['eventdate']);
}
As you surely noticed, this is for a custom post type ‘event’. However, I can’t retrieve the values and populate the fields. AFAIK, this involves inline-edit-post.js but I can’t find any way to use inlineEditPost to retrieve the custom field value. Even the post id is available in the JavaScript scope
add_action('admin_head-edit.php', 'ilc_quickedit_get');
function ilc_quickedit_get() { ?>
<script type="text/javascript">
jQuery(document).ready(function() {
jQuery('a.editinline').live('click', function() {
var id = inlineEditPost.getId(this);
alert("Post id: " + id);
});
});
</script>
<?php
}
Downloaded the Custom Field Template plugin to dissect the code and found that they are redefining portions of the inlineEditPost function, so I thought about doing the same thing. However, they appear to be doing it through an options array where a duplicate is stored.
If you have solved this, could you share what you’re using to retrieve the values for each custom field?
Ok, I got it, here’s the code:
and the code at the beginning of the admin.php file (which is the same file where all this code is located):
So far so good, maybe there are other ways to do it. Still need to deal with saving while in bulk editing mode. Could use a hand there too 🙂 Hope this is useful for someone.
This is untested code. See if it works for you. Basically, as you’ll read below, I globalize
$post
, check for your CPT, and then retrieve the custom fieldevent
from the post’s meta (returning a single value — as set by the “true” in the last parameter).The only thing you have to do is reference
$event
in your jQuery like so:{$event}
to output the value into the javascript. It’ll appear “static” but in reality it’s dynamic.P.S. I assigned your HTML code to a PHP variable to make it easier to read and allow you to quickly reference
$event
in the jQuery.