web-dev-qa-db-fra.com

Le widget de recherche se casse lors de l'utilisation de plusieurs boucles?

J'ai créé un modèle wordpress qui utilise deux boucles via l'objet WP_Query. Tout fonctionne bien sauf Widget de recherche. Cela fait trois jours que je m'arrache les cheveux. Googler comme un fou, mais je n'ai pas trouvé de solution. Par exemple dans mon barre de recherche J'écris: Premier chat (C’est le nom et le contenu de mon message dans la catégorie "chat") et cliquez sur Rechercher et RIEN ne se passe.

La chose étrange est la suivante: si je crée une boucle "normale" (boucle principale) au-dessus des deux autres boucles, la Widget de recherche FONCTIONNE, mais le problème est que maintenant mon "normal" (boucle principale) montre TOUT messages de mes deux autres boucles.
Quelqu'un peut-il m'aider, s'il vous plaît, ou donner une suggestion pour résoudre ce problème?
Lien vers mon site si vous souhaitez vérifier mon widget de recherche qui ne fonctionne pas :(
Index.php ressemble à ça:

 <?php get_header(); ?>
<?php get_sidebar('Main Sidebar'); ?>   
<div id="blogwrapper">  
<div id="blog">  
    <?php if (have_posts()) : ?>        
    <?php                             
    $paged1 = isset( $_GET['paged1'] ) ? (int) $_GET['paged1'] : 1;
    $paged2 = isset( $_GET['paged2'] ) ? (int) $_GET['paged2'] : 1;
    $args=array(

    'category_name' => 'cats',
    'paged' => $paged1,
    'posts_per_page' => 2,
    'order' => 'DESC'
     );
     $temp = $wp_query;
     $wp_query= null;
     $wp_query = new WP_Query($args);
     while ( $wp_query->have_posts() ) : $wp_query->the_post();
     ?>     
    <div class="post">  
    <div class="post_title">
    <h3><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3>
    </div>
        <div class="entry"> 

        <!--< ?php the_meta(); ?>-->

            <?php the_post_thumbnail(); ?>
            <?php the_content('Read on...'); ?>

            <p class="postmetadata">
            <?php _e('Filed under&#58;'); ?> <br/><?php the_category(', ') ?> <?php _e('by'); ?> <?php  the_author(); ?><br />
            <?php comments_popup_link('No Comments &#187;', '1 Comment &#187;', '% Comments &#187;'); ?> <?php edit_post_link('Edit', ' &#124; ', ''); ?>
            </p>
        </div>          
    </div>
    <?php endwhile;?>
    <?php else : ?>
    <h2>Not Found</h2>
    <p>Sorry, but you are looking for something that isn't here.</p>
    <?php endif; ?>
    <div class="navigation">
    <?php
     $pag_args1 = array(
        'format'  => '?paged1=%#%',
        'current' => $paged1,       
        'total'   => $wp_query->max_num_pages,      
        'add_args' => array( 'paged2' => $paged2 )
    );
    echo paginate_links( $pag_args1 );
    ?>
    </div>      
    <?php
$wp_query = null;
$wp_query = $temp;
wp_reset_postdata();
?>
    </div><!--/blog-->          
    <div id="blogs">    
    <?php            
$args2=array(

'category_name' => 'dogs',
'paged' => $paged2,
'posts_per_page' => 2
);
$temp = $wp_query;
$wp_query= null;
$wp_query = new WP_Query($args2);
while ( $wp_query->have_posts() ) : $wp_query->the_post();
?>
<div class="post">      
    <div class="post_title">
    <h3><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3>
    </div>
        <div class="entry"> 
            <?php the_post_thumbnail(); ?>
            <?php the_content('Read on...'); ?>
            <p class="postmetadata">
            <?php _e('Filed under&#58;'); ?> <?php the_category(', ') ?> <?php _e('by'); ?> <?php  the_author(); ?><br />
            <?php comments_popup_link('No Comments &#187;', '1 Comment &#187;', '% Comments &#187;'); ?> <?php edit_post_link('Edit', ' &#124; ', ''); ?>
            </p>
        </div>          
    </div>
    <?php endwhile;?>       
    <div class="navigation">        
    <?php
       $pag_args2 = array(
        'format'  => '?paged2=%#%',
        'current' => $paged2,
        'total'   => $wp_query->max_num_pages,
        'add_args' => array( 'paged1' => $paged1 )
    );
    echo paginate_links( $pag_args2 );
    ?>
    </div>      
    <?php
$wp_query = null;
$wp_query = $temp;
wp_reset_postdata();
?>              
    </div>
     </div><!--blogswrapper-->
   <?php get_footer(); ?>

Modifié Index.php avec la boucle principale qui fonctionne un peu (la boucle principale montre toutes les publications de deux autres boucles, mais le widget de recherche fonctionne ..)

 <?php get_header(); ?>
<?php get_sidebar('Main Sidebar'); ?>   
<div id="blogwrapper"> 
    <div id="blog">
       //Now Search Widget is WORKING but its's showing posts from 
       //other TWO LOOPS so it looks like a BIG mess:( 
    <?php if(have_posts()) : ?><?php while(have_posts()) : the_post(); ?>

    <div class="post">
    <h3><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3>

        <div class="entry"> 
            <?php the_post_thumbnail(); ?>
            <?php the_content(); ?>

            <p class="postmetadata">
            <?php _e('Filed under&#58;'); ?> <?php the_category(', ') ?> <?php _e('by'); ?> <?php  the_author(); ?><br />
            <?php comments_popup_link('No Comments &#187;', '1 Comment &#187;', '% Comments &#187;'); ?> <?php edit_post_link('Edit', ' &#124; ', ''); ?>
            </p>

        </div>
    </div>

    <?php endwhile; ?>

    <div class="navigation">
    <?php posts_nav_link(); ?>
    </div>

    <?php endif; ?>
</div>  
<div id="blog">  
    <?php if (have_posts()) : ?>        
    <?php                             
    $paged1 = isset( $_GET['paged1'] ) ? (int) $_GET['paged1'] : 1;
    $paged2 = isset( $_GET['paged2'] ) ? (int) $_GET['paged2'] : 1;
    $args=array(

    'category_name' => 'cats',
    'paged' => $paged1,
    'posts_per_page' => 2,
    'order' => 'DESC'
     );
     $temp = $wp_query;
     $wp_query= null;
     $wp_query = new WP_Query($args);
     while ( $wp_query->have_posts() ) : $wp_query->the_post();
     ?>     
    <div class="post">  
    <div class="post_title">
    <h3><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3>
    </div>
        <div class="entry"> 

        <!--< ?php the_meta(); ?>-->

            <?php the_post_thumbnail(); ?>
            <?php the_content('Read on...'); ?>

            <p class="postmetadata">
            <?php _e('Filed under&#58;'); ?> <br/><?php the_category(', ') ?> <?php _e('by'); ?> <?php  the_author(); ?><br />
            <?php comments_popup_link('No Comments &#187;', '1 Comment &#187;', '% Comments &#187;'); ?> <?php edit_post_link('Edit', ' &#124; ', ''); ?>
            </p>
        </div>          
    </div>
    <?php endwhile;?>
    <?php else : ?>
    <h2>Not Found</h2>
    <p>Sorry, but you are looking for something that isn't here.</p>
    <?php endif; ?>
    <div class="navigation">
    <?php
     $pag_args1 = array(
        'format'  => '?paged1=%#%',
        'current' => $paged1,       
        'total'   => $wp_query->max_num_pages,      
        'add_args' => array( 'paged2' => $paged2 )
    );
    echo paginate_links( $pag_args1 );
    ?>
    </div>      
    <?php
$wp_query = null;
$wp_query = $temp;
wp_reset_postdata();
?>
    </div><!--/blog-->          
    <div id="blogs">    
    <?php            
$args2=array(

'category_name' => 'dogs',
'paged' => $paged2,
'posts_per_page' => 2
);
$temp = $wp_query;
$wp_query= null;
$wp_query = new WP_Query($args2);
while ( $wp_query->have_posts() ) : $wp_query->the_post();
?>
<div class="post">      
    <div class="post_title">
    <h3><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3>
    </div>
        <div class="entry"> 
            <?php the_post_thumbnail(); ?>
            <?php the_content('Read on...'); ?>
            <p class="postmetadata">
            <?php _e('Filed under&#58;'); ?> <?php the_category(', ') ?> <?php _e('by'); ?> <?php  the_author(); ?><br />
            <?php comments_popup_link('No Comments &#187;', '1 Comment &#187;', '% Comments &#187;'); ?> <?php edit_post_link('Edit', ' &#124; ', ''); ?>
            </p>
        </div>          
    </div>
    <?php endwhile;?>       
    <div class="navigation">        
    <?php
       $pag_args2 = array(
        'format'  => '?paged2=%#%',
        'current' => $paged2,
        'total'   => $wp_query->max_num_pages,
        'add_args' => array( 'paged1' => $paged1 )
    );
    echo paginate_links( $pag_args2 );
    ?>
    </div>      
    <?php
$wp_query = null;
$wp_query = $temp;
wp_reset_postdata();
?>              
    </div>
     </div><!--blogswrapper-->
   <?php get_footer(); ?>
3
Dejo Dekic

Quelqu'un me tire dessus s'il vous plaît ... Comme c'est le premier thème que j'ai développé, je ne savais pas qu'il me fallait un search.php pour que ma forme fonctionne! Quoi qu'il en soit, j'ai créé search.php et inséré The Loop. Après cela, j'ai copié ce fichier dans mon thème et mon formulaire de recherche a fonctionné à merveille !!
J'espère que cela aidera quelqu'un d'autre :)
Mon search.php ressemble à ça:

<?php
/**
* The template for displaying Search Results pages.
*
* 
* 
* 
*/
    get_header(); ?>
<div id="blog">
    <?php if(have_posts()) : ?><?php while(have_posts()) : the_post(); ?>
    <div class="post">
    <h3><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3>
        <div class="entry"> 
            <?php the_post_thumbnail(); ?>
            <?php the_content(); ?>
            <p class="postmetadata">
            <?php _e('Filed under&#58;'); ?> <?php the_category(', ') ?> <?php _e('by'); ?> <?php  the_author(); ?><br />
            <?php comments_popup_link('No Comments &#187;', '1 Comment &#187;', '% Comments &#187;'); ?> <?php edit_post_link('Edit', ' &#124; ', ''); ?>
            </p>
        </div>
    </div>
    <?php endwhile; ?>
    <div class="navigation">
    <?php posts_nav_link(); ?>
    </div>
    <?php endif; ?>
    </div>
0
Dejo Dekic