Random WordPress Function

Learn about a new WordPress function every day!


Function Signature:

wp_post_mime_type_where

Function Description:

Converts MIME types into SQL.

Function Examples:

⚠️ Examples below are generated with GPT-3 once every hour. Do not take them too seriously.
Consider them as some extra input in your learning process - reason about them. Will it work? What could fail?
// Example 1: Retrieve all posts with the 'image/jpeg' mime type
$args = array(
    'post_mime_type' => 'image/jpeg'
);

$query = new WP_Query( wp_post_mime_type_where( $args ) );
// Example 2: Retrieve all posts with the 'video/mp4' mime type and exclude posts with a specific post type
$args = array(
    'post_mime_type' => 'video/mp4',
    'post_type' => 'post', // Exclude posts of type 'post'
);

$query = new WP_Query( wp_post_mime_type_where( $args ) );
// Example 3: Retrieve all posts with the 'application/pdf' mime type and limit the number of posts returned
$args = array(
    'post_mime_type' => 'application/pdf',
    'posts_per_page' => 10, // Limit the number of posts returned to 10
);

$query = new WP_Query( wp_post_mime_type_where( $args ) );