Delete child post and attachment links to parent post

There’s no way of doing this without “listening” for the responsible database query and altering it with the query filter, thanks to this line in wp_delete_post(): // Point all attachments to this post up one level $wpdb->update( $wpdb->posts, $parent_data, $parent_where + array( ‘post_type’ => ‘attachment’ ) ); The following will override the query and set … Read more

get_post orderby not working in plugin

You don’t get any ordering, because you are making multiple get_posts() calls and only retrieve a single post in each of them. You cannot order a single post. 🙂 You need to get rid of outermost loop and just pass a set of IDs (that would be your $instance[‘data’]) to retrieve via single get_posts() call.

All attachment pages give 404

Actually I got to the bottom of it. The problem was that I have installed the WPML plugin. But I forgot to install the WPML Media plugin. As soon as I installed it, the attachment pages started working again. In my opinion, this is unacceptable and I will escalate the issue to WPML team. If … Read more

Upload multiple image with media_handle_upload with multiple file field [duplicate]

You can try adding the input file field once and using then using jQuery to add more fields when clicking add more. Here are the steps Register your setting using register_setting function Create Menu using add_menu_page. This also requires a calback function Add the thickbox and media-upload script using wp_enqueue_script and wp_enqueue_style Use the call … Read more

How do I intercept and modify the functionality of wp_get_attachment_image()?

It might be a solution to string replace /wp-content/uploads with ” (empty) like for an example: Lets say: wp_get_attachment_image() returns=”/wp-content/uploads/myimage.png”; <?php echo str_replace(‘/wp-content/uploads/’, ”, wp_get_attachment_image()); ?> This will result in echo: ‘myimage.png’ Try this: function alter_image_src($attr) { $attr[‘src’] = str_replace(‘/wp-content/uploads/’, ”, $attr[‘src’]); return $attr; } add_filter( ‘wp_get_attachment_image_attributes’, ‘alter_image_src’); In your functions page (of theme).

Echo list attachment size in post

wp_get_attachment_thumb_url() doesn’t accept three parameters. It takes one– the attachment ID. And, as you might guess from the name of the function, it return the thumbnail URL *_thumb_url. If you’d have simply checked the Codex entry for the function you’d have seen that. If you’d check the Codex, you’d see several other things too Don’t … Read more

Looking to limit file attachment downloads

If your attachment is handled via the WP media library, each one has unique ID, just like Posts. When your users download the attachment by clicking the button, store a reference to that attachment ID in a user_meta setting and then update the button accordingly. Another option: https://easydigitaldownloads.com/

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)