• Resolved marcelvanm

    (@marcelvanm)


    Site: http://www.vmtweewielers.nl/2012

    In index.php I changes this

    <?php if (have_posts()) : ?>
    		<?php while (have_posts()) : the_post(); ?>
    			<div <?php post_class() ?> id="post-<?php the_ID(); ?>">

    into this

    <?php if (query_posts( 'cat=26' )) : ?>
    		<?php while (have_posts()) : the_post(); ?>
    			<div <?php post_class() ?> id="post-<?php the_ID(); ?>">

    and now the search is not working anymore. When I use a search term it it doesn’t seem another page (with results) is opened but the title in the browsertab is changed to “search results”.

    What did I break? And more important: how can I fix it? 🙂

Viewing 5 replies - 1 through 5 (of 5 total)
  • I don’t know what you were trying to do by adding the extra query, but it replaces the original query that caused index.php to be called.

    You get an entirely different query that causes index.php to always show category 26. I doubt that is what you want. Please explain what you were trying to do.

    Thread Starter marcelvanm

    (@marcelvanm)

    I was trying to just show posts from category 26 on the homepage when you arrive at the website as a user.

    But off course I didn’t understand that this would interfere with the searchpage 🙂

    Since I can’t see all of your code, I can’t be sure exactly where to put this. If your code has a test for ‘if ( have_posts() )’, the code should go just before that. If not, it should just replace your ‘if (query_posts(“cat=26”) :’ line.

    <?php if ( is_home() ) :
       global $wp_query;
       query_posts( array_merge( $wp_query->query,
                    array( 'cat' => 26 ) )
                  );
    endif; ?>

    Note that the endif has moved up from where it was before.

    Thread Starter marcelvanm

    (@marcelvanm)

    That worked. I see only posts from category 26 now and also the search function works as it should thanks very much!

    Here’s the piece of code this was about. Notice that I just put your piece of code just before the if(have_posts()) test.

    If your problem has been solved, please use the dropdown on the right to mark this topic ‘Resolved’ so that anyone else with this question can see that there is a solution.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Search not working after slight change to index.php’ is closed to new replies.