How to fetch only media that was already attached to a post/page?

A similar approach to your post_parent idea is to add a filter to posts_where: function bbg_filter_out_non_attachments( $sql ) { global $wpdb; // Maybe do some conditional logic to decide whether to filter this query, then… return $sql . ” AND $wpdb->posts.post_parent != 0 “; } add_filter( ‘posts_where’, ‘bbg_filter_out_non_attachments’ ); Another technique is to do a … Read more

Check if post has gallery images/media

No Need for SQL queries in the template. function wpse_72594_get_attachments( $id, $mime=”” ) { $args = array( ‘post_type’ => ‘attachment’, ‘post_mime_type’ => $mime, ‘post_parent’ => $id ); $attachments = get_posts($args); if ($attachments) return $attachments; return false; } Then call the function like this (300 is the post ID): wpse_72594_get_attachments(300), grabs all attachments wpse_72594_get_attachments(300, ‘image’ ), … Read more

How to get media objects

Have you tried to use get_children() function? Edit: All media attached to any post is treated as children of it. The function wp_get_attachment_image() will only return images. With the function get_children() you’ll be able to get all the media, images or anything else. In the above link, you can find some examples.

Customizing default Mediaelement player

Okay so i did manage to add some custom css selectively on pages that load the medialement player by adding this to my functions.php file: function custom_player() { wp_enqueue_style( ‘custom-player’, get_stylesheet_directory_uri() . ‘/wp-mediaelement.css’ ); $custom_css = ” /*here goes the css*/ “; wp_add_inline_style( ‘custom-player’, $custom_css ); } add_action( ‘wp_enqueue_scripts’, ‘custom_player’ ); Like this by using … Read more

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