Forums

Search Media Does Not Work (10 posts)

  1. manadeprived
    Member
    Posted 11 months ago #

    I have a custom theme made for my site yet search for images in the media library does not work. I believe this is theme specific because if I apply the default WordPress theme (Twenty Eleven), search works as intended.

    My question is where can I find the part of the code that deals with this specific function?

    Thanks!

  2. esmi
    Theme Diva & Forum Moderator
    Posted 11 months ago #

    Start by removing any javascript or jQuery calls (or deregisters) in the theme.

  3. manadeprived
    Member
    Posted 11 months ago #

    esmi, you are awesome.

    I was able to narrow the bug to one line.

    /* LIMIT SEARCH RESULTS */
    function vibeExcludePages($query) {
    if ($query->is_search) {
    $query->set('post_type', 'post');
    }
    return $query;
    }
    add_filter('pre_get_posts','vibeExcludePages'); <--Deleting this line makes it work.

    Not entirely sure what this line actually does though, so I am afraid I am breaking something if I do this.

  4. manadeprived
    Member
    Posted 11 months ago #

    Hmmm, searching up the code on Google seems to show that this is code used to exclude pages from the search. Somehow it affects my Media Library searches too.

  5. esmi
    Theme Diva & Forum Moderator
    Posted 11 months ago #

    Try changing it to:

    if( !is_admin() ) add_filter('pre_get_posts','vibeExcludePages');

  6. manadeprived
    Member
    Posted 11 months ago #

    esmi,

    If I understand your code correctly, would that make it so that search only works properly if you an administrator? I have editors that I wish for search to work for them as well.

    Thanks!

  7. esmi
    Theme Diva & Forum Moderator
    Posted 11 months ago #

    No - the change I made ensures that the code won't be loaded into the admin area.

  8. Alkorr
    Member
    Posted 10 months ago #

    Hi esmi! I just posted on this thread:
    http://wordpress.org/support/topic/cant-search-in-media-library

    Are the two solutions the same ones? Because I don't get where to put either you code or the other one... Damn, I wish I understood PHP better...

    Thanks for your help!

  9. Alkorr
    Member
    Posted 10 months ago #

    Me again, I found out eventually.

    Thanks Esmi, you rock, as always! :)

  10. esmi
    Theme Diva & Forum Moderator
    Posted 10 months ago #

    Glad I could help :-)

Reply

You must log in to post.

About this Topic

Tags