Free Custom WordPress WP Query Generator And Loop Builder

This free tool will help you generate a custom WP Query for displaying specific posts based on the arguments you define.  It will also build the loop to display your results.  It can be a simple query that is filtered to display posts in a specific category, by tags, etc.  Or create a complex wp_query by filtering to display posts that contain specific terms within a taxonomy or the results of a custom field.

Keyword Search
Limit results to posts containing this keywordTooltip text
Post Type
any, post, page, my_custom_post_type
Post Status
publish, pending, draft, auto-draft, future, private, inherit, trash, any
Author
Show posts only by a specific author or authors using author ID. or comma-separated list of IDs.
Author Name
Show posts only for a specific author, using the author's "user_nicename".
Category
Show posts only for a specific category or categories. Enter category ID, or comma-separated list of IDs.
Category Name
Show posts only for a specific category, using the category's slug
Tag
Show posts only for a specific tag, using the tag's slug.
Tag ID
Show posts only for a specific tag, using the tag's ID
Define whether you want your query results to be paginated.
No paging?
Show all posts (true) or paginate (false)
Posts per page
The number of posts per page. Use -1 to display all posts
Posts per archive page
Number of archive posts per page. Overrides 'posts_per_page' when is_archive(), or is_search().
Paged
Order
Default is DESC
Orderby
Defaults to date (post_date)none
id
author
title
name
type
date
modified
parent
rand
comment_count
relevance
menu_order
meta_value
meta_value_num
Text for when no results found
What to show when there are no matching posts
Show Post Thumbnail?
In the results loop, show the post's image?
Show Post Titles?
In the results loop, show the post's title?
Show Post Excerpts?
In the results loop, show the post's excerpt?
Narrow results based on the year, month, and/or day posts were published.
By Year
Show all posts by year
By Month
Show all posts by month (numeric)
By Day
Show all posts by day (numeric)
More complex date queries ("30 days ago", "after a specific date", etc) can be made by using WordPress date_query https://developer.wordpress.org/reference/classes/wp_query/#date-parameters combined with datetime relative formats https://www.php.net/manual/en/datetime.formats.relative.php. Some examples:
  • 7 days ago
  • one month ago
  • yesterday
  • 12 months ago
  • today
Before
Show posts before
After
Show posts after
Narrow results based on taxonomy. Based on https://developer.wordpress.org/reference/classes/wp_query/#taxonomy-parameters/div>
Taxonomy
Filter by custom field key, regardless of custom field value
Field
Select taxonomy term by term_id, name, slug or term_taxonomy_id.
Terms
Input depends on the "Field" previously selected
Narrow results based on the value of a custom field. Based on https://developer.wordpress.org/reference/classes/wp_query/#custom-field-post-meta-parameters
Meta Key
Filter by custom field key, regardless of custom field value
Meta Value
Filter by custom field value, regardless of custom field key
Meta Compare
Uses operator for comparison=
!=
>
>=
<
<=
LIKE
NOT LIKE
IN
NOT IN
BETWEEN
NOT BETWEEN
NOT EXISTS
REGEXP
NOT REGEXP
RLIKE

The Code

<?php
// WP_Query arguments
// Generated by UseWordPress.com
$use_wp_args = array(
'tax_query' => array(
array(
)
),
'date_query' => array(
array(
)
),
);
// The Query
$use_wp_query = new WP_Query( $use_wp_args );
// The Loop
if ( $use_wp_query->have_posts() ) {
while ( $use_wp_query->have_posts() ) {
$use_wp_query->the_post();
// do something
}
} else {
// no posts found
}
// Restore original Post Data
wp_reset_postdata();
?>

Where do you put this custom wp_query code?

That depends on what you need it for. If you are using it to customize the way WordPress displays results in your archive.php or category.php file, you will replace the existing wp_query with this one. If you have created a new post that you want to use to display your filtered post results, you can create a new file using WordPress template hierarchy structure, single-{post-type}-{slug}.php (ie single-post-my-post-page-slug.php), which is based on the single.php file. View WordPress Codex for template hierarchy at https://developer.wordpress.org/themes/basics/template-hierarchy/
Available for Amazon Prime