Support » Plugin: Wordpress File Upload » How to provide post_title, post_content. post_excerpt
How to provide post_title, post_content. post_excerpt
-
Hi, yes it can be done however it requires custom code and implementation of some plugin’s hooks. I can help you with this. Do you have these attributes (title, description etc.) as additional fields in the upload form?
Regards
Nickolas
Yes I defined the following fields:
Title
Caption
Description
Photo Date
Categories
Tags (separate with space)Can you show how to map to the standard image fields, categories, tags?
Hi, I have created a hook for you that adds title, caption and description to the image based on the fields, but I have some questions:
a. Photo Date: you mean the upload date or something else?
b. Categories and Tags. The default WordPress Media Library does not provide categories and tags. Are you using any plugin for setting them? If not, we can configure the plugin to create them.Nickolas
Thanks for working on this… 🙂
a) Photo date – the date the photo was taken
b) yes I have been experimenting with a plugin (MLA) that adds the standard post categories and tags, or custom taxonomies just for images. I think both approaches have merit, but leaning toward the custom taxonomy approach.a) Regarding the Photo date, there is no default field in an attachment for when a photo was taken. So, is this going to be a custom field?
Nickolas
Yes I changed the “Photo Date” field to be called “Created” and will save as a custom field.
Ok here is an initial hook that will add title, caption, description and created date.
if ( isset($GLOBALS["WFU_GLOBALS"]["WFU_DEBUG"]) ) $GLOBALS["WFU_GLOBALS"]["WFU_DEBUG"][3] = "ON"; if (!function_exists('wfu_debug_wfu_process_media_insert_function_handler')) { function wfu_debug_wfu_process_media_insert_function_handler($res, $file_path, $userdata_fields, $page_id) { $wp_upload_dir = wp_upload_dir(); $filetype = wp_check_filetype( wfu_basename( $file_path ), null ); $title = ( isset($userdata_fields[0]) && trim($userdata_fields[0]["value"]) != "" ? trim($userdata_fields[0]["value"]) : preg_replace( '/\.[^.]+$/', '', wfu_basename( $file_path ) ) ); $caption = ( isset($userdata_fields[1]) ? $userdata_fields[1]["value"] : "" ); $description = ( isset($userdata_fields[2]) ? $userdata_fields[2]["value"] : "" ); $created = ( isset($userdata_fields[3]) ? $userdata_fields[3]["value"] : "" ); $attachment = array( 'guid' => $wp_upload_dir['url'] . '/' . wfu_basename( $file_path ), 'post_mime_type' => $filetype['type'], 'post_title' => $title, 'post_content' => $description, 'post_excerpt' => $caption, 'post_status' => 'inherit' ); $attach_id = wp_insert_attachment( $attachment, $file_path, $page_id ); require_once(ABSPATH . 'wp-admin/includes/image.php'); $attach_data = wp_generate_attachment_metadata( $attach_id, $file_path ); $attach_data["WFU User Data"]["Created"] = $created; $update_attach = wp_update_attachment_metadata( $attach_id, $attach_data ); $filedata = wfu_get_filedata($file_path, true); if ( $filedata != null ) { $filedata["media"] = array( "type" => "data", "attach_id" => $attach_id ); wfu_save_filedata_from_id($filedata["general"]["idlog"], $filedata); } $res["result"] = 'R'; $res["output"] = $attach_id; return $res; } add_filter('wfu_debug-wfu_process_media_insert', 'wfu_debug_wfu_process_media_insert_function_handler', 10, 4); $GLOBALS['wfu_debug-wfu_process_media_insert'] = "1"; }
You need to add it at the end of functions.php file of your theme.
It is left for me to add category and tag taxonomies. Let me know that we are ok so far.
Nickolas
- The topic ‘How to provide post_title, post_content. post_excerpt’ is closed to new replies.