wp_query in infinite loop

I’m trying to do this loop, but it is going infinite

I just need to show some results on <li> tags. I’m editing the loop.php to do this and the function if(function_exists('wp_custom_fields_search')) wp_custom_fields_search(); just return a form of one plugin I had created.

Read More

Can you help me with it?

<?php
        $queryA = new WP_Query($args1);
        $queryB = new WP_Query($args2);

        $args1 = array (
        'orderby' => 'title', 
        'order' => 'ASC', 
        'category_name' => 'lojas',
        'posts_per_page' => '-1',
        );

        $args2 = array (
        'orderby' => 'title', 
        'order' => 'ASC', 
        'category_name' => 'gastronomia',
        'posts_per_page' => '-1',
        );  


        if ($queryA->have_posts()) {
            if(function_exists('wp_custom_fields_search')) wp_custom_fields_search();
            while($queryA->have_posts()) : $queryA->the_post();
                echo '<li>';
                echo '<span class="nome">';
                the_title();
                echo '</span>';
                echo '<span class="end">';
                echo get('endereco');
                echo '</span>';
                echo '<span class="tel">';
                echo get('telefone');
                echo '</span>';
                echo '</li>';
            endwhile;
        } 


        if ($queryB->have_posts()) {
            if(function_exists('wp_custom_fields_search')) wp_custom_fields_search('preset-1');
            while($queryB->have_posts()) : $queryB->the_post();
                echo '<li>';
                echo '<span class="nome">';
                the_title();
                echo '</span>';
                echo '<span class="end">';
                echo get('endereco');
                echo '</span>';
                echo '<span class="tel">';
                echo get('telefone');
                echo '</span>';
                echo '</li>';
            endwhile;
        }       


    ?>

Related posts

Leave a Reply

1 comment

  1. I must admit from your code I don’t see first-hand what might cause the infinite loop, however you can drastically reduce your code which might help you find your error:

    $defaultArgs = array (
        'orderby' => 'title', 
        'order' => 'ASC', 
        'posts_per_page' => '-1',
    );
    $queries = array(
        array(array('category_name' => 'lojas'), NULL),
        array(array('category_name' => 'gastronomia'), 'preset-1'),
    );    
    $customFiledsSearch = function_exists('wp_custom_fields_search');
    foreach ($queries as $query)
    {
        list($args, $param) = $query;
        $wpQuery = new WP_Query($args + $defaultArgs);
        if ($wpQuery->have_posts()) 
        {
            if ($customFiledsSearch)
            {
                wp_custom_fields_search($param);
            }
            while ($wpQuery->have_posts()) : $wpQuery->the_post())
            {
                echo '<li>', 
                       '<span class="nome">',
                         the_title();
                       '</span>',
                       '<span class="end">', 
                         get('endereco'), 
                       '</span>', 
                       '<span class="tel">', 
                         get('telefone'), 
                       '</span>', 
                     '</li>';
    
            }
        }
    }
    

    Maybe this helps you to find your error.