WP_Query Generator


Use this tool to create custom code for WordPress Query with WP_Query class.


  • Fill in the user-friendly form.
  • Click the “Update Code” button.
  • Copy the code to your project.
  • Or save it as a snippet and share with the community.


If you are still learning how to use this tool, check out the following examples:

The variable used in the code.
Show The Loop.
Display post by ID.
Display post by slugs.
Display page by ID.
Display page by slugs.
Display child-pages of a parent-page id.
Display posts by post type.
Display posts by post status.
Display password protected posts.
Display posts with a particular password.
Display posts by author ID
Display posts by author 'user_nicename'.
Show all posts or use pagination.
Show posts in page number X.
Number of post to show per page.
Number of post to show per archive page.
Show or ignore sticky posts.
Number of post to displace or pass over.
Ascending or Descending order.
Sort retrieved posts by.
Select from your saved WP_Tax_Query snippets.
Select from your saved WP_Date_Query snippets.
Select from your saved WP_Meta_Query snippets.
Display posts if user has the appropriate capability.
Display posts with/without caching post information.
Display posts with/without caching post term information.
  Save Snippet
// WP_Query arguments
$args = array(
	'post_type'              => array( 'post' ),
	'author_name'            => 'rami',
	'order'                  => 'DESC',
	'orderby'                => 'date',

// The Query
$query = new WP_Query( $args );