-
Searching pages in WordPress 1.5
Gepubliceerd op 20 februari 2005 in Programming. 2 reactiesUpdate (march 6, 2004): David B. Nagle made a plugin which gives the same results as this hack, but does it the right way, using the plugin system. Use it instead of hacking as described below.
A few days ago version 1.5 of WordPress was released. One of the interesting new features is the addition of pages. You use pages for static content on a site, which means you can now use WordpPress to build a larger part of you site. Very useful.
But one thing I don’t understand is why pages are left out of search results? Through a thread on the support site I found a bug report that states
This is intended behaviour until we revamp search.
. So I looked for a solution.Hacking the search function
493 this piece of code starts:
if ($this->is_page) { $where .= ' AND (post_status = "static"'; } else { $where .= ' AND (post_status = "publish"'; }
Change it to the following:
// 2005-02-20, Rob Schluter: Hack to search posts & pages. if (!empty($q['s'])) { $where .= ' AND ((post_status = "static" or post_status = "publish")'; } else{ if ($this->is_page) { $where .= ' AND (post_status = "static"'; } else { $where .= ' AND (post_status = "publish"'; } } // end hack
That’s it, put the changed file on your server and the search should work for pages also.
- php
- search
- wordpress
2 Reacties
-
-
Kevin Haryett 6-03-2005 (8:16)
Awesome fix for a search dillema that I have hoped someone would come up with. It works well on my site. You should submit this to the Bug tracker for addition to the codebase.
Thanks
David B. Nagle 6-03-2005 (2:41)
Thank you for this hack! I liked it enough that I rolled it together into a plugin, Search Pages. I have a link in the plugin (and everywhere else) crediting you with the hack.