WordPress Search Results for Multiple Post Types

The wp_get_attachment_image_src() function expects you to also pass some kind of attachment ID plus it doesn’t grab the image HTML that we need so instead we should use wp_get_attachment_image(). IF a post has a post thumbnail, grab it.ELSE IF the post has any attached images, grab the first one.ELSE maybe show a placeholder? I’ve defined … Read more

get_attached_media() on author page not working

I assume that you have a simple misunderstanding of what this function actually does and what it should be used for: get_attached_media() simply fetches all child posts for a given posts: if ( ! $post = get_post( $post ) ) return array(); $args = array( ‘post_parent’ => $post->ID, ‘post_type’ => ‘attachment’, ‘post_mime_type’ => $type, ‘posts_per_page’ … Read more

How to do meta_query for attachments?

I went with custom taxonomy instead of custom meta field and it works great (although I am still not sure why meta_query didn’t work) I have saved custom taxonomy term for each attachment wp_set_object_terms($post->ID, $slug, ‘image_category’ ); And custom query args are $args = array( ‘post_type’ => ‘attachment’, ‘posts_per_page’ => 44, ‘post_status’ => ‘inherit’, ‘post_parent’ … Read more

How can I store a file in the database in the same way WordPress and ACF do?

ACF doesn’t store any file in Database, it simply provides meta fields with user friendly interface. You can however, store them yourself. To store a field, you need to be familiar with PHP a bit. Here’s how saving a meta field happens, by using the add_post_meta() function: add_post_meta ( $post_id, ‘meta_key’, ‘meta_value’, $is_unique ); There … Read more

wp_mail not sending attachment

You said in your OP that the absolute path was returned, but you are using the ‘baseurl’ value which gives you a URL to the file that you can browse to. That’s a URL, which is not the same as the path to the file in the file system. This line is your issue: $attachment … Read more

Post edit – Media Library – Only get images from current post

This will lock uploads to “Uploaded to this post” and will not show “All media items” or other options in WordPress media panels. Add this code to your function.php file add_action( ‘admin_footer-post-new.php’, ‘firmasite_mediapanel_lock_uploaded’ ); add_action( ‘admin_footer-post.php’, ‘firmasite_mediapanel_lock_uploaded’ ); function firmasite_mediapanel_lock_uploaded() { ?> <script type=”text/javascript”> jQuery(document).on(“DOMNodeInserted”, function(){ // Lock uploads to “Uploaded to this post” jQuery(‘select.attachment-filters … Read more

Get PDF in media by ID

Don’t know why, but doing this worked… In my search.php, no problem. In content-search.php, no result. while (have_posts()) : the_post(); $attachment = wp_get_attachment_url(get_the_ID()); set_query_var(‘document’, $attachment); get_template_part(‘template-parts/content’, ‘search’); endwhile; EDIT As mention @Dave Romsey, do add_action( ‘pre_get_posts’, ‘attachment_search’ ); instead of add_filter( ‘pre_get_posts’, ‘attachment_search’ );

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