New answers tagged

2

I suggest you to use the more newer media manager dialog; WordPress will hanlde all the image upload stuff, including generating intermediate sizes and attachement metadata. Here a working example (it is a quick example built from a previous code, it may needs some tweaks to be used on production): add_action( 'admin_enqueue_scripts', 'load_wp_media_files' ...


3

I've finally solved! The problem was that simply using update_user_meta( $user_id, 'mycoverimage', $_POST[ 'mycoverimage' ] ); The image was saved without generating attachment metadata. In fact, checking my table, it got only usermeta id which is not the attachment id. So I had to change a bit my uploading function according to codex with the use of ...


1

Not sure it will make a difference, but as you just want one value you can get get_var instead of get_col. I tweaked the query slightly to what I know works: function get_attachment_id($image_url) { global $wpdb; $attachment = $wpdb->get_var($wpdb->prepare("SELECT ID FROM ".$wpdb->prefix."posts WHERE post_type='attachment' AND guid='%s'", $...


2

That area of all admin screens is where admin notices are displayed, so you could generate an admin notice. Here's a suitable function and hook: function wpse_233031_admin_notice() { ?> <div class="notice notice-info"> <p>Your message here!</p> </div> <?php } function wpse_233031_hook_admin_notice() { ...


0

You need the attachment ID - which is the same as the "thumbnail ID" - not the post ID. It's confusing. Maybe by WP 5.0 they'll update the nomenclature! So, I think this'll work: function attached_image_content( $column_name, $post_ID ) { if ( $column_name == 'foobar' ) { //Change the image size from default 'thumbnail' here $...


0

The solution is actually very simple, it's just one line of code, since i realized that attachment id is actually same as any other post id i can retrieve user id based on post field. $post_author_id = get_post_field( 'post_author', $post_id ); This gets the user id of the user who uploaded image and $post_id is image attachment id So further checking ...


0

I am using something similar in my website, to only show media attachements uploaded by other users, if this is an option for you, you can use the code or you can edit it to match your need but the truth is that it gets the user ID in the same way it would get it from a post with post_author Here's the code you can test it and see if this will work good for ...


0

Some passing by can eventually find an answer to this question here. Same community but more proactive there. Weird.



Top 50 recent answers are included