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
- Some doubts about how the main query and the custom query works in this custom theme?
- Is there a way to exclude the content from the post variable to save on RAM usage?
- How to query post by user role?
- How do I create my own nested meta_query using posts_where / posts_join?
- Using Query Posts With Multiple Post Types And A Taxonomy
- Help altering a query to exclude all but standard post format
- Post Title displaying but not in the wrapped HTML I need
- Two posts in same div – WP loop
- Sort Popular Posts by Views for the Last Week
- Inserting Post Using wp_insert_post. How to Fill Yoast Plugin SEO Fields
- How to get current post id of a custom post type in a loop using template singel-{custom type}.php?
- Query sticky posts with thumbnails
- ‘category__and’ for custom taxonomy?
- Separate Posts and Custom Post Type in Custom Taxonomy archive template
- Exclude first 2 posts with meta_key from loop
- Pagination on custom query
- Ordering terms before displaying posts
- Querying posts with meta value that begins with a certain pattern
- Adding Variables to post query
- Unable To Get Published posts using query_posts
- Read More is not working in query posts
- How to insert content from another Custom Post type into Post?
- How to reverse the order of WordPress blog posts?
- Order a query result by a numeric meta key even if it does not exist, but put the posts with meta key first
- Trouble with get_next_post() get_previous_post() returning null
- popular post weekly and monthly
- Multiple loops without repeating content
- Get posts between custom dates
- Authors List page : how to exclude posts from certain category
- Two loops, one AJAX loop, exclude posts in first loop from second loop, loops are in different files
- Query a WordPress page by its title (which has a parent page)
- query_posts() vs get_posts() multiple loops [duplicate]
- post_parent array doesn’t work
- Using WP_Query and Query_post for the loop?
- query_posts pagination will always show identical content
- WordPress Custom Query to get Most Commented Posts in the Past 7 Days
- Get posts that do not have the same tags as current
- Loop through posts of only 2 statuses
- Posts are not looping through correctly
- Query posts only with actual text content (not including shortcode or images)
- Display specific posts on home page
- Restrict query_posts by Date?
- Sort post by custom field numeric value
- Notting but the latest post content keeps on being loaded
- query_posts doesnt show pages with given ID when post_type => page
- How to put posts in pages using query posts
- Query add html after set amount of posts?
- Custom loop off by one post
- How to setup blog page to render blog posts minus afew categories
- How to get max value of filtered query post
- Ordering of posts, 2020 Year showing as next event when should be last
- ACF meta_key and meta_value break loop
- Problem with my loops
- Sort loop by custom field from different post type
- How to add in WP_Query to every 3 posts displayed? [duplicate]
- Use special template for the first post in the loop
- Custom loop – Isolating post meta output depending on current query taxonomy terms
- show latest authors blog post
- query multiple posts by id using a string parameter, not array()
- Query posts in a category and include only one post per author?