How about this:
$my_query = new WP_Query(array(
'post_type'=> 'custom_type',
'post_status' => 'publish',
'meta_key' => 'my_custom_field',
'meta_value' => 'custom field value'
));
if($my_query->have_posts()):
while($my_query->have_posts()):$my_query->the_post();
//All the post stuff here.
endwhile;
endif;
wp_reset_postdata();
Check this out.
Related Posts:
- How to query_posts using meta_query to orderby meta_key AND have a secondary sort by date?
- How to return results of a get_posts() in explicitly defined order
- Modify main WordPress loop with a parse_query filter
- How should I intercept the main query and inject custom join / order by / group by criteria
- get_post_meta causes database queries
- How to query ‘posts_per_page’ to display a different blog posts index template?
- Dynamically excluding current page id
- Using database meta_values to calculate new post order using pre_get_posts or a ‘request’ hook
- Order by meta_key with two meta_queries
- How to order results by date and meta key?
- Sort Posts by Multiple Meta Values [duplicate]
- ACF Custom Field WP_Query, but need to get all posts, if field doesn’t exist
- Static Front-Page Excerpts
- Is it possible to query_posts using post__in and then Loop through them in the ordered they were queried?
- query_posts() ALWAYS displays something?
- Single meta key with multiple meta value in like comparison
- How to remove a plugin filter’s priority on specific loops (custom queries)?
- Custom loops, sticky posts, and pagination nightmare
- meta_query check for meta value in key which holds an array of values
- How to provide meta_key array to wp_query?
- Modify loop but keep the original query, what am I doing wrong?
- When to use WordPress loop or Foreach loop?
- Post per page not working if no category specified
- Meta query stopped working
- Calling Posts from Specified Cat
- Most Effective Method? Exclude Category and Number of Posts Per Page
- How do I query based on the modified date?
- Script that gets the first tag of post and query all other posts with the same tag
- Custom query looking at multiple custom fields and properly sorting
- How to add an “or” instead of and “and” (&) in a WordPress query?
- Modify main loop query for paged and meta key
- Create a Loop with Posts Ordered by Most Recent Comments
- Tax query get first product with attribute value in pre_get_posts
- Ordering Posts By Meta Data
- query_posts() with multiple meta data comparisons
- query_posts and sub pages?
- The_content display a different content from a previous loop
- WordPress loop problem: Multiple loops, index.php and is_paged causing duplicate posts on next page
- Including post data in a sidebar occurring outside of and before the Loop
- Multiple loops with / without sticky posts and different post limits
- How to Get All Posts with any post status?
- posts_per_page no limit
- Nested meta_query with multiple relation keys
- How do I exclude a custom taxonomy from the post loop
- How can i get count from query post
- Some doubts about how the main query and the custom query works in this custom theme?
- query_post by title?
- Why query_posts() isn’t marked as deprecated?
- Alternative to query_posts for main loop? [duplicate]
- How to get posts published between a date and today?
- how to query posts by category and tag?
- Using WP_Query to Query Multiple Categories with Limited Posts Per Category?
- Using meta_query, how can i filter by a custom field and order by another one?
- Order by meta value or date?
- How do I query by post format in WordPress 3.1
- Display posts of the last 7 days
- Is there a way to exclude the content from the post variable to save on RAM usage?
- Filtering posts by post meta data
- WP_Query vs get_posts
- Query posts by custom taxonomy ID
- Fail to compare dates in meta_query
- Display/query post formats
- Display products from specific category in shop page
- How to query post by user role?
- Display all posts from specific categories on a page
- Help to condense/optimize some working code
- Order posts by ID in the given order
- How to set posts per page using WP_Query()
- query_posts exclude a meta key
- How do I create a random post that will last for a day
- Ensuring sticky posts are retrieved first (without using two queries)?
- Query Multiple Post types each with own meta query
- Determine if more posts are available than was asked for in `query_posts()`?
- Get the number of posts from the current page results
- How to exclude latest x posts from a paginated query?
- query_posts() in function makes global $wp_query out of sync?
- WordPress Custom Query to show posts from last x years
- Limiting query_posts to 1, regardless of sticky post?
- How to make “sticky” pages (and query by them)
- Build a content and excerpt grid loop with paging and options for # of posts
- Query posts: how to exclude results if post is in multiple categories
- Query Custom Meta Value with Increment
- query_posts ->using meta_compare / where meta value is smaller or greater or equals
- Display content from a specific category
- Problem with ‘post__not_in’
- Is `query_posts` really slower than secondary query?
- How to order posts by descending comment count on taxonomy page?
- Are there any scenarios where the query_posts may be used?
- Sort posts alphabetically by custom field value, insert divider between different letters
- Is it better practice to use query_posts, WP_Query, or get_posts to create various custom loops within a Page?
- WP 5.8 “Query Loop” block: where to place custom query?
- Perform query with meta_value date
- Sort X categories by last update and show image
- Custom Post Type “Event”: chronological list of recurring events
- Meta Query with date and time on the same Day before given time
- using post__in allow duplicate post id
- Pagination on archive.php page
- Why is it necessary to call rewind_posts() when using the loop more than once? [duplicate]
- Retrieving 3 latest post from each of 5 different custom post types
- WordPress Custom Query