Support

Account

Home Forums Backend Issues (wp-admin) How to create custom query for posts with specific file extension

Unread

How to create custom query for posts with specific file extension

  • I’m trying to put together a custom wp_query. In my case, I’m trying to pull back the following:

    – All published posts of type “media_resources” that have a file extension of .pdf in the file field.

    In this case, the posts have a field group of “Resources Post” inside which is the field “file” (field type is file), where uses can upload any type of file they want.

    This is what I have so far, which is not quite correct:

    `// Get only media_resources with pdf files
    $q3 = get_posts(array(
    ‘fields’ => ‘ids’,
    ‘post_type’ => ‘media_resources’,
    ‘post_status’ => ‘publish’,
    ‘posts_per_page’ => -1,
    ‘meta_query’ => array(
    array(
    ‘key’ => ‘file’,
    ‘value’ => ‘pdf’,
    ‘compare’ => ‘LIKE’
    )
    )
    ));`

    I did find this page, which was somewhat helpful, but I’m not clear if I’m technically looking for a sub-field or not or what the issue is.

    Please advise. Thank you.

Viewing 1 post (of 1 total)

You must be logged in to reply to this topic.

We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.