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
- Keep featured content post in homepage with original order
- How to get posts published between a date and today?
- How to get post ID of the current page/post inside a widget?
- 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
- Trying to query all posts in category 4
- Display 3 posts with different HTML markup using a loop
- Getting posts from some categories plus some individual posts
- Get posts from current category?
- Change content off every sixth element
- How to assign a post to a post parrent?
- query for filtering published posts?
- get parent fields title, content excerpt etc
- AWS usage queries
- Pull in posts using post meta for REST API
- How to show multiple posts thumbnail, title and date in widget
- Add checkbox in admin post list – show checked post in widget
- Create a List of Widgets, where each widget holds three attributes
- How to merge the content of posts that have the same title?
- 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
- How to fetch courses in all languages in WordPress?
- Multisite how to display merged posts from two sites and sort by latest date?
- How do i bring out post category name in my widget?
- How to show post views shortcode data for each post on Posts List Page?
- post__in no longer works in wordpress 5.0.3
- How can I use query_posts to loop through posts and construct my own content?
- How to display particular categorie’s post which associated to specific user?
- Assign a day of the week to post, e.g: Assign Monday to post and have it only appear when the day is Monday
- Show 5 posts and than 3 posts offset with pagination
- wp_query args with relation
- WP_Query to get posts in a specific tag or has post_format
- Make recent post display recent updated, instead of recent published
- Manipulate query to show specific post
- Querying posts from current category, using a variable as array argument
- How to correctly escape data
- Posts on Sidebar only
- Use special template for the first post in the loop
- 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?
- Creating widget – ask for selecting a post in the admin panel
- How to display most popular posts from certain category in sidebar?
- Need help writing loop to display posts by categories in separate divs
- Get posts by category or author
- Sort / Filter Queries
- get_page_by_title() not working if special characters are present
- Modify WordPress loop after it has been run
- Post List Widget with custom posts and editing the Read More Link
- Query post category & remove any post id
- show latest authors blog post
- Hide first blog post in content and output it in widget
- get “read more” with custom DB query like you would with WP Query
- How to get only current images of a post
- Ordering posts alphabetically by meta keys and title
- Why I obtain this WP_Query strange behavior trying to select posts having a specific tag?
- Why I have this strange behavior when I try to exlude the featured post from posts visualization?
- How do I control the fallback query after the original query returned cero posts?
- Remove duplicated posts in the loop if post has more than one category
- How to pass multiple checkbox values to wordpress query?
- Adding a category at even positions on main loop with modified pagination
- How to limit the number of results for all query_posts on mysite
- 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?
- wp_query select if have comments
- Creating pages and getting their values from the database table
- How to limit post query to only return a total count of items with certain post statuses?
- Not displaying any articles on a custom made file
- How can to use the players from the Media Widgets in the body of a post to play audio and video files
- How to have more post in a page than in your home page
- wp trim function not working
- Change from all posts to specific categories post on main page?
- How to add a widget area between blog posts in Genesis Framework?
- query_posts different amount of posts per page [duplicate]
- wordpress pinboard theme [closed]
- Count words for all posts by all authors
- Word count for all posts of all authors
- Do I need to create a multisite for querying posts from multiple WordPress sites?
- Dynamic archive of posts by date
- Sort Posts Alphabetically Based on Specific Category (Divi)
- How to change url of posts?
- Output number of WordPress posts remaining until a post milestone is reached
- Image inside the content is replaced with featured image from my older post
- How to show related posts by detecting the current category?
- Display posts on a custom page from only a specific category?
- Why does ‘get_the_ID’ work outside of the loop?
- WordPress Post Query Using Custom native MySQL like St_Distance_Sphere
- How to display blog posts per category using tabs or accordion?