PHP code example of wp-forge / wp-loop

1. Go to this page and download the library: Download wp-forge/wp-loop library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

wp-forge / wp-loop example snippets




foreach ( wp_loop() as $post ) {
	



$query = new WP_Query( [ 'post_type' => 'post' ] );

foreach ( wp_loop( $query ) as $post ) {
	



$query = new WP_Query( [ 'post_type' => 'post' ] );
$posts = $query->posts;

foreach ( wp_loop( $posts ) as $post ) {
	



$query = new WP_Query( [
	'post_type' => 'post',
	'fields'    => 'ids',
] );

$post_ids = $query->posts;

foreach ( wp_loop( $post_ids ) as $post ) {
	



$query    = new WP_Query( [ 'post_type' => 'post' ] );
$iterator = new ArrayIterator( $query->posts );

foreach ( wp_loop( $iterator ) as $post ) {
	



if( have_posts() ) {
    // For global query approach
}

if( $query->have_posts() ) {
    // For custom query approach
}

if( ! empty( $posts ) ) {
    // For post or post ID approach
}

if( $iterator->valid() ) {
    // For iterator approach
}