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 a specific MIME type
$args = array(
    'post_type' => 'attachment',
    'post_status' => 'inherit',
    'posts_per_page' => -1,
    'post_mime_type_where' => array(
        'type' => 'image/jpeg'
    )
);
$attachments = new WP_Query($args);
// Example 2: Filter posts by multiple MIME types
$args = array(
    'post_type' => 'attachment',
    'post_status' => 'inherit',
    'posts_per_page' => -1,
    'post_mime_type_where' => array(
        'relation' => 'OR',
        array(
            'type' => 'image/jpeg'
        ),
        array(
            'type' => 'image/png'
        )
    )
);
$attachments = new WP_Query($args);
// Example 3: Exclude posts with a specific MIME type
$args = array(
    'post_type' => 'attachment',
    'post_status' => 'inherit',
    'posts_per_page' => -1,
    'post_mime_type_where' => array(
        'relation' => 'NOT',
        array(
            'type' => 'application/pdf'
        )
    )
);
$attachments = new WP_Query($args);