How do I get attachment_id?

Ok, all those hipercomplex functions can be reduced to one simple command: attachment_url_to_postid You only need to parse the image url to retrieve the attachment id: <?php $attachment_id = attachment_url_to_postid( $image_url ); echo $attachment_id; ?> That’s all you need.

How to Add Reminders/Notes to New Post Meta Boxes

You should never edit the core files of WordPress. Instead you should only ever edit Plugin files and or Theme files (Plugins or Themes folder) One of the easiest was to achieve this would be via jQuery; jQuery(‘<div/>’, { id: ‘your-note’, text: ‘Add up to 5 tags…etc’ }).appendTo(‘#tagsdiv-post_tag .inner’); Save the above into a alerts.js … Read more

How to force one column layout on custom post type edit page?

There is a filter called get_user_option_meta-box-order_{$page} where $page is the name of the post type. Just make sure that submitdiv is the last value in the array: add_filter( ‘get_user_option_meta-box-order_post’, ‘wpse25793_one_column_for_all’ ); function wpse25793_one_column_for_all( $order ) { return array( ‘normal’ => join( “,”, array( ‘postexcerpt’, ‘formatdiv’, ‘trackbacksdiv’, ‘tagsdiv-post_tag’, ‘categorydiv’, ‘postimagediv’, ‘postcustom’, ‘commentstatusdiv’, ‘slugdiv’, ‘authordiv’, ‘submitdiv’, ) … Read more

Post custom metabox textarea using wp_editor

There is at least 1 issue with using wp_editor in a meta box, as discussed in ticket #19173(Good read on the subject of wp_editor and meta boxes). TinyMCE gets all messed up if you move the meta box that contains it (specifically, if TinyMCE’s location in the DOM is changed). You can, however, use the … Read more

Using TinyMce with textareas in meta boxes on custom post types

Here’s a pastebin with your code included. Get the old value of the tinyMCE $meta_biography = get_post_meta( $post->ID, ‘meta_biography’, true ); Call the TinyMCE Editor wp_editor( $meta_biography, ‘biography’, array( ‘wpautop’ => true, ‘media_buttons’ => false, ‘textarea_name’ => ‘meta_biography’, ‘textarea_rows’ => 10, ‘teeny’ => true ) ); Save The Editor Value or if nothing is there … Read more

Multiple Custom Metabox Help

Solve a complex Problem (rationally) To solve complex problems, there is a kind of standardized/well known approach: Divide your complex problem into a set of smaller problems. Smaller problems are easier to solve. If you have solved each smaller problem you most often have solved your complex problem already. Locate and Divide into Parts So … Read more

Sample code for validating custom metabox?

Straight from the WP Codex @ http://codex.wordpress.org/Function_Reference/add_meta_box, you call the save_post hook and specify the function that will be run to validate/save your data: /* Do something with the data entered */ add_action(‘save_post’, ‘myplugin_save_postdata’); Then you define that function, which will automatically be passed the post id. Additionally, you can access the $_POST array to … Read more