You can check if the query returned any posts by doing $home_query->have_posts()
.
$home_query = new WP_Query( array('posts_per_page' => get_query_var('posts_per_page'),'paged' => $current_page ) );
if( !$home_query->have_posts() ){
// Do this if $home_query had no posts.
}
Related Posts:
- Hiding posts in a list from specified categories
- Query function not executed between element [closed]
- Function to execute when a post is moved to trash .
- Get current post id in functions.php
- How to publish a post with empty title and empty content?
- How to exclude latest x posts from a paginated query?
- Query posts distinct authors
- How to get previous 10 days post from a specific date – WP Query
- How to Display Post View Count
- Function to show random posts from a category
- How would I get 1 latest post from a query for 5 posts?
- Exclude posts with empty post_content in wp_query
- Create cron job without a plugin?
- Improving WP_Query for performance when random posts are ordered
- Reset Popular post query?
- Why WP_Query(‘showposts=5’) shows only 1 post?
- is there a way to show the the post title after the image?
- Blog post per page setting conflicting with custom WP_Query?
- Change post order random through out the entire WordPress
- How to exclude latest x posts from a paginated query?
- How to do set post permalinks using 6 digit random unique function?
- Random ajax load only works with posts_per_page set to -1
- posts_per_page option limits the number of Gallery items
- 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?
- Nested WP_Query breaking loop
- WordPress query_posts by tag doesn’t work anymore(?)
- Every second post different class in blog view
- why the same code got different results when using query_posts in functions.php and index.php
- Query for first 3 posts to change the look and feel
- How to get posts published on the latest date?
- How to only publish posts with image in it
- Shortcode with ‘year’ parameter
- On what hook can I get the queried object’s final state?
- wp_query with ajax
- How to give classname to post if post has no content?
- WP_Query: Show 10 posts in date order, first three random
- Get post by tag
- Random posts that always include a particular post?
- Related Posts function not working
- WordPress post filter menu
- Echo the number of posts being displayed
- WordPress query portfolio posts
- Same post appears in related Posts?
- Display 3 posts with different HTML markup using a loop
- Change content off every sixth element
- how to show comments only author which send own posts in wordpress
- 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
- the wp_post_update isn’t working all the time
- Function is printing twice – any suggestions?
- Multisite how to display merged posts from two sites and sort by latest date?
- Show 5 posts and than 3 posts offset with pagination
- wp_query args with relation
- Manipulate query to show specific post
- Show all posts from the tags without having to set all of them
- How to correctly escape data
- Sort / Filter Queries
- 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
- 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
- wp_query select if have comments
- wp trim function not working
- How to modify this function to exclude also the post belonging to a specific category?
- query_posts different amount of posts per page [duplicate]
- Filters do not work when there are multiple (one works)
- WP_Query of Category Not Showing First Post
- Get latest author posts inside the loop
- WordPress displays post on subcategory only
- saving/reading custom field value does not work – no value gets POSTed
- How to get posts ordered by using their categories?
- Limiting post list by taxonomy
- Why does WordPress search returns same number of results for every search query?
- Creating a related posts section in wordpress inside a default post
- WP_Query articles order by offset in collumns
- Internal linking to posts permalink fail because of spaces and stripe at postname
- How to display WP Query filters?
- Finding a post’s slug
- Have h2 tag not show up if there are no blog posts
- Trying to query all posts in category 4
- Getting posts from some categories plus some individual posts
- Sidebar limiting to 10 posts?
- Get posts from current category?
- WordPress as CMS: How to manage/handle images assigned to a post as full-sized background images in a slideshow?
- Making a wordpress page print friendly
- How to assign a post to a post parrent?
- Is there a function to get post info for any publish_status by post ID?
- query for filtering published posts?
- Actions to use when flushing cache (when posts are added / deleted / modified)
- How Can I Always Display A Particular Post First Using WP_Query?
- Help on conditional statement to accompany wp_insert_post function please?
- get parent fields title, content excerpt etc
- How to implement a WordPress comments function?
- How to add content above footer in posts from specific category
- Set Default Post as Parent Child (Nested) Relation