top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

What is the use of loop in Worpdress Where we used it?

+2 votes
354 views
What is the use of loop in Worpdress Where we used it?
posted Apr 28, 2015 by Vrije Mani Upadhyay

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

0 votes

The Loop are php code used by WordPress to display posts. Using The Loop, WordPress processes each post to be displayed on the current page.check below sample code.
<?php

if ( have_posts() ) {

while ( have_posts() ) {

the_post();

//

// Post Content here

//

} // end while

} // end if

?>
answer Apr 29, 2015 by Rahul Singh
Similar Questions
0 votes

I am working on an API integration. Now I have a problem. First I am trying to show all specific city hotels, which city is having in my database. First FOREACH worked as well its search hotel by my database city, but on Second FOREACH I am trying to show First FOREACH city hotels show only match hotel which hotels matches from database and its not worked.

My Task is: 1st search by city which city have on my database and 2nd time search in 1st time hotel and showed hotel only match my database hotel.

1st foreach:

if($RowCount>0){
            foreach($Results as $Result){
                foreach($api_array as &$value){
                    if($Result['county'] == $value['address']['city']){ 
                        $final_array[] = $value; 
                    } 
                } 
            }
        }

2nd foreach:

foreach($final_array as &$display){
            var_dump($display);
            if($Result['hotel'] == $display['property_name']){ 
                $final_array2[] = $display; 
            }  
        }

full code:

foreach($array as $api_array){
        $final_array = array(); 
        $Results = $wpdb->get_results( "select * FROM hotels where county = '$countyname'",ARRAY_A );
        $RowCount  =  $wpdb->num_rows;

        if($RowCount>0){
            foreach($Results as $Result){
                foreach($api_array as &$value){
                    if($Result['county'] == $value['address']['city']){ 
                        $final_array[] = $value; 
                    } 
                } 
            }
        }
        foreach($final_array as &$display){
            if($Result['hotel'] == $display['property_name']){ 
                $final_array2[] = $display; 
            }  
        }
    }
...