Anytime you call WP_Query, be sure to filter for only published posts.
Also as a general guide, for any custom queries that you expect or could have more than one result for, try to always pass arguments for:
- Publish status
- Limit / number of results
- Field to sort by
- Sort order
Refer to the codex page (https://codex.wordpress.org/Class_Reference/WP_Query) for a full list of arguments you can pass.
Related Posts:
- Move position in post list for a custom checkbox column
- How to show related posts by category
- the_author() returns empty string
- Display all posts from specific categories on a page
- How to exclude latest x posts from a paginated query?
- Display content from a specific category
- How to display posts by current user/author in a custom page template?
- post_name empty after wp_insert_post
- WordPress Posts Out Of Order after 3.1 Update
- Query only Posts from Both of Two Category?
- Insert custom div between posts
- Only display posts with comments
- Which file displays the date archive?
- WordPress get posts by date without query_posts
- How to Display Post View Count
- Different amount of posts on homepage than paged pages
- Featured Posts for Category Pages
- Cannot Update A Post, 404 Error
- Hiding posts in a list from specified categories
- How would I get 1 latest post from a query for 5 posts?
- Can I set and show “important” post in my blog?
- Exclude posts with empty post_content in wp_query
- Create dropdown list post
- I would like to give special promotion for the first 100 posts in my blog? Can anyone tell me how to do that?
- previewing my posts on static page?
- Inserting custom data to the_post() during loop
- Ajax load more button in Recent posts widget
- is there a way to show the the post title after the image?
- Category Foreach keeps looping?
- Blog post per page setting conflicting with custom WP_Query?
- How to exclude latest x posts from a paginated query?
- Random ajax load only works with posts_per_page set to -1
- Display an author’s posts on his own author page
- remove post and categories/tags count from right now dashboard widget
- How to make multiple sections in home pulling posts category wise?
- wp_posts table: safely remove unused columns to save database storage
- Query Posts by Custom Field
- Order posts alphabetically: how to set order=asc in mysql query?
- How to order posts in an arbitrary order?
- How to get posts from a current post’s month?
- Wrong post title displayed from loop
- While loop articles – if statement order
- Conditionals if tags exist?
- WordPress website loads more posts than expected
- Get the amount of posts on a current page
- Posts – display all posts except a post by an ID
- query post limits
- why the same code got different results when using query_posts in functions.php and index.php
- Archive template combined with post slider and regular posts
- How to get posts published on the latest date?
- How to only publish posts with image in it
- How to check in functions.php if there is data in a WP_Query?
- Post Filtering by GET URL parameters
- WP_Query: Show 10 posts in date order, first three random
- Get post by tag
- Random posts that always include a particular post?
- Bootsrap carousel for post
- Get postlist for each category using query_posts?
- How to save posts position on homepage after random function?
- Echo the number of posts being displayed
- Exclude a category of posts in author template
- WordPress displays post on subcategory only
- Trying to query all posts in category 4
- Get posts from current category?
- Change content off every sixth element
- Add checkbox in admin post list – show checked post in widget
- Custom Fields – How to get the list of a specific active widget each time it rendered
- get posts, run a custom query, and join the results
- Show posts from two specific category in WP_Query
- How to create loop of posts except post ID defined via ACF field
- Displaying all posts from other sites on the network on one site
- Multisite how to display merged posts from two sites and sort by latest date?
- post__in no longer works in wordpress 5.0.3
- How to display particular categorie’s post which associated to specific user?
- Manipulate query to show specific post
- How to correctly escape data
- Posts on Sidebar only
- Blog posts not displaying on blog posts page
- Repeating post how to solve this
- Sort Events by Venue Title – Sort Post set by related post ids
- How do I create a ‘selection’ criteria list’ that will then dictate which posts are generated when the user presses search?
- How to display most popular posts from certain category in sidebar?
- Get posts by category or author
- Post List Widget with custom posts and editing the Read More Link
- Hide first blog post in content and output it in widget
- get “read more” with custom DB query like you would with WP Query
- Why I obtain this WP_Query strange behavior trying to select posts having a specific tag?
- How to pass multiple checkbox values to wordpress query?
- Adding a category at even positions on main loop with modified pagination
- How to use in_category?
- How to get all post titles starting with numbers and symbols?
- How to inject a post within a loop
- How to get alphabetic listing x other posts, based on first letter post?
- Creating pages and getting their values from the database table
- How to have more post in a page than in your home page
- wp trim function not working
- How to add a widget area between blog posts in Genesis Framework?
- query_posts different amount of posts per page [duplicate]
- Do I need to create a multisite for querying posts from multiple WordPress sites?
- How to change url of posts?