Tag Info

New answers tagged

0

I found a nice snippet at this site for your functions.php that does the trick: add_shortcode( 'gallery', 'file_gallery_shortcode' ); function file_gallery_shortcode( $atts ) { $atts['link'] = 'file'; return gallery_shortcode( $atts ); } I'd actually been looking unsuccessfully for the same thing, so I'm glad you asked.


0

Although it shouldn't change based on your theme, this may be an issue caused by how this new theme handles images. As of WordPress 3.5, when you add a media object such as an image, there's a sidebar that appears on the right. Underneath the "Attachment Details" (preview, title, caption, etc.) there's a section called "Attachment Display Settings". In ...


0

This is, what finally fixed it for me: apply_filters('wp_handle_upload', array( 'file' => $file_path, 'url' => $file_url, 'type' => $file_type), 'upload'); Explanation: I'm not quite sure why this fixed the error for me, but I assume that this either has something to do with plugins using the wp_handle_upload hook or that the ...


0

I got it! The result will show all attachments in a specific term inside term's archive page. Thanks Chip! <?php $queried_object = get_queried_object(); $term_id = $queried_object->term_id; global $wp_query; $original_query['tax_query'] = array( array( 'taxonomy' => 't-arte', 'terms' => $term_id, 'field' => 'id', ),); $original_query ...


0

I think the problem is that you're passing the wrong arguments to the $attachments query, causing you not to get the intended posts in the $attachments query. Here's what you're doing: $args = array( 'post_status' => 'inherit', 'numberposts' => 0, 'post__not_in' => array_merge($do_not_duplicate,get_option( 'sticky_posts' )), ...


0

Your solution (edited incorrectly into the question) should be workable but you should be able to accomplish the same with fewer queries. Pull your portfolio IDs-- note the fields argument. Then pull your attachments with those IDs as the parent post. Then you only loop over the one image array. That works out to two primary queries. To wit: $query = ...


0

Thanks @timocouckuyt, that works fine but you also need this one for the /wp-admin/upload.php link : add_filter('pre_get_posts', 'hide_posts_media_by_other'); function hide_posts_media_by_other($query) { global $pagenow; if( 'upload.php' != $pagenow || !$query->is_admin ){ return $query; } if( !current_user_can( 'manage_options' ) ) { global ...


0

You can hook onto add_attachment and force the slug to work off the filename like so: Update: To uppercase the slug, you'll need to add a temporary filter onto wp_unique_post_slug. You can't simply use strtoupper( $slug ) as WordPress sanitises (lowercases) it within the update function. /** * Force attachment slug to ignore title from metadata (if any). ...


0

Milo got me on the right track. If anyone else happens to have this issue the code I used is: /** * Redirect broken attachment links to 404 */ function ww_404_broken_links(){ global $wp_query; if(is_attachment()){ $attachment_path = get_attached_file( get_the_ID() ); //If the file doesn't exist on the server show 404 ...


2

All media (somewhat incorrectly) in the $wpdb->posts table will be "attachments" whether actually attached or not. "Attachments" that are actually attached will have a post_parent other than 0, so what you need are all of the attachments that have a 0 in the post_parent column, if I understand you. $args = array( 'post_type' => 'attachment', ...


0

<?php if ( $post->post_type == **'post type name'** && $post->post_status == 'publish' ) { $attachments = get_posts( array( 'post_type' => 'attachment', 'posts_per_page' => -1, 'post_parent' => $post->ID, 'exclude' => get_post_thumbnail_id() ) ); if ( $attachments ) { ...


1

At some point in the process you could do the following: Generate attachment ID from URL, like here Save attachment ID to custom field value using add_post_meta() Retrieve attachment using custom field value later with get_post_meta()


0

Use the string function instead, and print it only if you get something: $previous = adjacent_image_link(true, 'thumbnail' ); if ( ! empty ( $previous ) ) print 'before' . $previous . 'after';


2

When you just have raw image files, that you want to assign to a post, wp_insert_attachment will do the job. With attachments already present in your database you can use wp_update_post to set the attachment's post_parent. Like this: wp_update_post( array( 'ID' => $attachment_id, 'post_parent' => $parent_post_id, )); To recieve a post's ...



Top 50 recent answers are included