Does search only work with posts? (9 posts)

  1. andreacimatti
    Posted 10 years ago #

    I'm wondering if there is a way to search all the wordpress site, Pages and Posts, or if the search features only handle posts? If so are there any workarounds to this?

  2. Sridhar Katakam
    Posted 10 years ago #

    May be put up a Google search box? It searches throughout the site.

  3. Ajay
    Posted 10 years ago #

    It only handles posts as of now, though there is a Search Pages plugin/hack for this.

  4. andreacimatti
    Posted 10 years ago #

    good ideas both. I'll look into them.

  5. kurniawan
    Posted 10 years ago #

    I tried to change the classes.php file (it's in your wp-includes folder) since this is the class that constructs the query that will get your posts esp the function &get_posts(). I don't really know if this is alright or there's a safer workaround, but right now it's working for me.

    I use WP2 and in line 601 of classes.php (in function &get_posts()) I added these 2 lines:

    } elseif ($this->is_search) {
    $where .= ' AND (post_status = "publish" OR post_status = "static")';

    So it goes like this (start from line 595):

    if ( $this->is_attachment ) {
    $where .= ' AND (post_status = "attachment")';
    } elseif ($this->is_page) {
    $where .= ' AND (post_status = "static")';
    } elseif ($this->is_single) {
    $where .= ' AND (post_status != "static")';
    } elseif ($this->is_search) { //added line
    $where .= ' AND (post_status = "publish" OR post_status = "static")'; //added line
    } else {
    $where .= ' AND (post_status = "publish"';
    if (isset($user_ID) && ('' != intval($user_ID)))
    $where .= " OR post_author = $user_ID AND post_status != 'draft' AND post_status != 'static')";
    $where .= ')';


    NB: You also need to customized your search.php file so that after every page you won't see "Posted in <default_category> | <Comments>"

  6. moshu
    Posted 10 years ago #


    Yep, having a plugin for that I think modifying the core files is NOT a good idea. Most users will forget about it and at the next upgrade they'll cry about borked sites.
    Use or make a plugin :)

  7. kurniawan
    Posted 10 years ago #

    Yeah. I thought about it too. I've made several plugins myself but I haven't found a good way for this issue. This is just a pragmatist solution.
    The problem that I have in mind is how am I going to alter the construction of posts from query results made by the function &get_posts() using a plugin. Or maybe a workaround on The Loop? Or maybe I'm just too dumb for this..
    What's the plugin/hack that have succeded in doing this? I've looked around but maybe I missed it somewhere.
    Thanks for the reply.

  8. moshu
    Posted 10 years ago #

    I am not a coder, so I don't have an answer for your questions. Here is the plugin I use in several installs for searching Pages:

  9. kurniawan
    Posted 10 years ago #

    Whoa.. I've seen the plugin. And I feel really stupid now. Why didn't I think of that before? Thanks.

Topic Closed

This topic has been closed to new replies.

About this Topic


No tags yet.