Tag Info

New answers tagged

1

I think what you are after is get_post_meta() and not a custom query. REASONS: The results from custom fields are cached and extremely streamline when it cone to performance. You can read this answer I have done recently which will explain everything You are trying to get the custom field attached to a post only in a single post page. This is what ...


0

That's because wp_mail expects the attachment to be a filename (filepath) that it can attach and send. You are supplying a string containing the contents of the file: function create_csv() { $filepath = '/path/to/the/file.csv'; $fd = fopen($filepath, 'w'); if($fd === FALSE) { die('Failed to open temporary file'); } $records = ...


3

Thank you for the response everyone. I played around with macemmek's solution and I think it led me to an even better solution: add_filter( 'wp_unique_post_slug_is_bad_attachment_slug', '__return_true' ); That is all that is needed. This will automatically 'skip' the default assigned slug on any attachment. So an attachment that might normally get the ...


3

You may hook wp_unique_post_slug() and append some string to the original slug if the post is an attachment type. The original slug based on post title will remain free. UPDATED after Rachel Baker's comment: original slug suffix is some random string. It does not guarantee uniqueness but may be enough for simple use cases. add_filter( ...


1

Tom's comment is correct, in that this is normal behaviour and there is not much you can do to stop it. But you can change slugs after things are uploaded/created. While you shouldn't do this if the links are known/publicised/listed on search engines, if you're just trying to fix this problem occasionally after an upload then you can edit the slug of the ...


2

You could create a small plugin for this, here is an small example that will try to download and attach a file based on the url in the excerpt field for the post: add_action('publish_post', 'auto_featured_image_publish_post'); function auto_featured_image_publish_post($post, $post_id) { // check if this post is saved for the first time ...


0

Mike's answer is correct, of course, but $alt_text = get_post_meta($post->ID, '_wp_attachment_image_alt', true); may return an empty string. wp_get_attachment_image, however, does always get an alt_text. The Wordpress team applies the following trick, first, checking for the post_except, then obtaining the title. if(empty($alt_text)) // If not, Use the ...


1

Here's something I wrote because my clients were using very high quality pngs, when they could be more lossy jpgs for web. Note this still preserves the original image, only changes the thumbnails. Add this to your functions.php <?php //Force PNG Thumbnails into JPGs add_filter('wp_generate_attachment_metadata','force_png_to_jpg'); function ...



Top 50 recent answers are included