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

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

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

How Does WordPress Remember Metabox Positions?

WordPress saves them in the databas in wp_usermeta as serilized array. For the dashboard all are registered in meta-box-order_dashboard if the meta-box(s) are in metaboxhidden_dashboard they will not be shown. The order will be as saved in database and if not in metaboxhidden_dashboard. Example the dashboard: KEY: meta-box-order_dashboard VALUE: Array ( [normal] => dashboard_right_now,dashboard_recent_comments,dashboard_incoming_links,dashboard_plugins [side] … Read more

Creating a metabox to upload multiple images

That depends entirely on what you mean by “attach.” Each WordPress post can already have multiple media attachments – photos, documents, etc. You upload these using the built-in uploader and they’ll all be marked as “attached” to that specific post ID. You can refer to these later programatically elsewhere. For example, the following code will … Read more

Best practices for meta box placement?

It is hard to declare best practices here. The placement depends on the content of the metabox: an editor field would be too narrow usually in the side column; two small checkboxes on the other hand will look lost in the main column. To understand where which box will be placed, let’s use a small … Read more

Remove the Yoast SEO Post Metabox [closed]

On remove_meta_box is a note: Because you can’t remove a meta box until it’s been added, it’s important to make sure your call to remove_meta_box() happens in the right sequence. WordPress SEO adds meta boxes on add_meta_boxes action with default priority – 10, which run after admin_init, so that won’t remove them. Instead you need … Read more

Remove the Featured Image Meta Box

I haven’t had time to test this but this looks like it should work for you. add_action(‘do_meta_boxes’, ‘remove_thumbnail_box’); function remove_thumbnail_box() { remove_meta_box( ‘postimagediv’,’post’,’side’ ); } Check this for more info. Edit: The main change here is that you need to attach the function to do_meta_boxes instead of admin_menu