In this lesson we will discuss get_posts  and also touch the famous WordPress LOOP

<?php
/*
Plugin Name: Query Posts
Plugin URI: http://agilesolutionspk.com/training
Description: It shows the use of custom post type
Version: 1.0
Author URI: 
*/

function custom_init() {
    $args = array(
      'public' => true,
      'label'  => 'Books'
    );
    register_post_type( 'book', $args );
}
add_action( 'init', 'custom_init' );

add_action( 'admin_menu', 'my_admin_menu' );

function my_admin_menu(){
	 add_menu_page( 'Get Posts', 'Get Posts', 'list_users', 'get_posts_example', 'get_posts_fnc');
}

function get_posts_fnc(){
	//get posts demo
	
	$args = array(
		'post_type'        => 'book',
		'post_status'      => 'publish',
		
	);
	
	$mybooks = get_posts($args);
	
	
	foreach($mybooks as $book){
		echo "<div>". $book->post_title . "</div>";
		echo "<div>". $book->post_content . "</div>";
	}
	
	while (have_posts()){
		the_post();
		the_title();
		the_content();
	}

}