WordPress.org

Support

Support » How-To and Troubleshooting » Breaking Search with index page hack

Breaking Search with index page hack

  • Hi. The ability to search breaks when I turned on hack_file and created a my_hacks.php file with the following code to display a specific category when index.php is displayed:
    <pre>
    if (!isset($cat))
    $cat = 1;
    </pre>
    Actually, search doesn’t break completely, only the category specified in the hack is searched. I’m assuming there’s code somewhere that specifies which categories to search. Can someone tell me if I can fix this and still keep the hack? Thanks!!

Viewing 7 replies - 1 through 7 (of 7 total)
  • After the code above in your my-hacks file, try adding this:
    <pre>
    // Unset $cat if searching:
    if (isset($s))
    $cat = '';
    </pre>

    http://wiki.wordpress.org/index.php/show-one-category-on-front-page
    Explains exactly what I think youre looking for.

    OK, now I find out that with the above lines are inserted in “my_hacks.php”, when archives are selected only the posts present in category 1 are displayed. I tried adding a few permutations such as:
    <pre>
    if (isset($archives)) $cat = ”;
    if (isset($a)) $cat = ”;
    </pre>
    but with no luck. I’ve searched through all the files looking for any other string that calls “archives” but can’t find anything obvious. Help!

    Damn, you’re right (I have this enabled on my site too).
    What’s going on?

    Is if (isset($a)) $cat = ”; the right syntax? Is $a really the variable that matters here?
    I might be able to hack something out, but I’m not sure of the relevant variables.

    I’m hoping someone can tell us. I don’t know enough about WP or php; I was just trying to copy the syntax used for the search variable.

    I found it! (by trial and error and finding the variable listings for archives in the template_functions.php file.
    is restored to the index page hack by adding:
    <pre>
    if (isset($m)) $cat = ”;
    </pre>
    Therefore the entire code for the my_hacks.php file is:
    <pre>
    if (!isset($cat) && !isset($p)) $cat = 1;
    if (isset($s)) $cat = ”;
    if (isset($m)) $cat = ”;
    </pre>
    Now if I could just figure out my emailing problem….(http://wordpress.org/support/3/3042), I’m good to go.

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Breaking Search with index page hack’ is closed to new replies.
Skip to toolbar