Support

Account

Home Forums General Issues Post Object field: Search not returning result for media/attachment

Solved

Post Object field: Search not returning result for media/attachment

  • Hello,

    Long time ACF (PRO) user here. First off, many thanks for a fantastic product. ACF have made it so much easier working with WP. 😀

    I’ve run into a problem with search in the post object field not returning any results for media/attachments. I can find and select media / attachments in the listing, but get “no results” when using search. See images below.

    I can search for pages and posts just fine. But get no result when searching for media / attachments. The client have many posts and attachments (pdfs) so scrolling through the whole list to find a document gets quite cumbersome.

    Does search in post object / relationship field only return post types “page” and “post”? If so, how can I add “attachment” as a searchable post type?

    Grateful for any help! Thanks!

  • Hi @joaonev

    I’ve just tested it on my installation but failed to reproduce this issue. Maybe there’s something on your site that modify the search query. Could you please try to reproduce the issue on one of the WordPress’ stock themes (like Twenty Sixteen) with only ACF activated? If it disappears, then you can activate the theme and plugins one by one to see which one causes the issue.

    Thanks 🙂

  • Hi James,

    Many thanks for taking the time to test this issue. You are absolutely right!

    Just tested it myself on a new WP installation, with only ACF Pro and the search in the post object field works as expected. Search were able to find Media / attachments. :/

    Will update this thread if I find whats causing this..

  • Ok, found the problem. Had some code inside functions.php (from a previous project) messing with the search query..

    // Extend search to include pages and posts
    function wp_search_filter( $query ) {
        if ( $query->is_search ) {
            $query->set( 'post_type', array('post','page') );
        }
        return $query;
    }
    add_filter('pre_get_posts','wp_search_filter');

    Removed it, and now everything is working as expected! Happy times! 😀

    Thanks again James for pointing me in the right direction. Cheers!

Viewing 4 posts - 1 through 4 (of 4 total)

The topic ‘Post Object field: Search not returning result for media/attachment’ is closed to new replies.