Post being redirected to attachment post

I think the reason for this is the get_page_by_path() check inside the WP_Query, because it’s checking for both page and attachment slugs, in this case. So if we have both an attachment and a post with the someslug postname and visit: example.tdl/someslug then get_page_by_path() will generate the following query: SELECT ID, post_name, post_parent, post_type FROM … Read more

Show Post ID in “Find Posts or Pages” box in Media Library?

You cannot do that with pure PHP. The table is created in wp-admin/includes/ajax-actions.php::wp_ajax_find_posts(), and there is no filter. But look at the radio buttons: name=”found_post_id” value=”‘ . esc_attr($post->ID) You can print a script on the action admin_footer-upload.php that extracts the post ID from the values and adds a new column to the table. Here is … Read more

Insert Media – Attachment – Link to : Remove the “attachment page” option

These options are hardcoded into the tmpl-attachment-display-settings Underscore media template in the /wp-includes/media-template file: <script type=”text/html” id=”tmpl-attachment-display-settings”> <h3><?php _e(‘Attachment Display Settings’); ?></h3> …cut… <select class=”link-to” data-setting=”link” <# if ( data.userSettings && ! data.model.canEmbed ) { #> data-user-setting=”urlbutton” <# } #>> <# if ( data.model.canEmbed ) { #> <option value=”embed” selected> <?php esc_attr_e(‘Embed Media Player’); ?> … Read more

Get attachment ID of author_meta image – Attachment Metadata

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’ ); function … Read more

custom fields for attachments?

Here is a tutorial that shows how to add custom fields to the attachments/media gallery/thickbox/iframe/whatever-you-call it overlay. I’ve successfully used it, but have not yet taken it much further by adding radio buttons/checkboxes/etc or messed with limiting the changes to particular post types, but that all looks completely doable too. Here is the code from … Read more

Get post id by attachment id?

get_post_ancestors can give you the ID of the object an attachment is associated with: $attachment_id = 42; $parent = get_post_ancestors( $attachment_id ); echo $parent[0]; // $parent will be an array

How can I hide media library images from general users?

To let the current users only view his/her uploaded attachments, add the following code to your themes actions: add_filter( ‘posts_where’, ‘devplus_wpquery_where’ ); function devplus_wpquery_where( $where ){ global $current_user; if( is_user_logged_in() ){ // logged in user, but are we viewing the library? if( isset( $_POST[‘action’] ) && ( $_POST[‘action’] == ‘query-attachments’ ) ){ // here you … Read more

How do I exclude all images from a wp_query?

Pretty much the solution is to include all mimes except images. WordPress has a nifty little function where it keeps all it’s accepted mime-types called get_allowed_mime_types() ( cleverly named ) which returns an Array() of mimes. All we need to do is get the difference between the returned array and the array of mime-types we … Read more