I’ve never seen it done before but the logic of the PHP IF/ELSE should mean you could simply plug a new query in after the ELSE:
if ( have_posts() ) : while ( have_posts() ) : the_post();
get_template_part ( 'templates/post', 'main' );
endwhile;
else:
$the_query = new WP_Query( $args );
if ( $the_query->have_posts() ) :
while ( $the_query->have_posts() ) :
$the_query->the_post();
endwhile;
endif;
endif;
This is untested on my end.
Related Posts:
- How to go about combining dropdowns / filter queries?
- How do I set the Stewart Search Template to return only published posts in the result
- Trying to get all links in my posts
- How to fix pagination for custom loops?
- Remove the Homepage Query
- A search for ‘0’ returns results
- Is `query_posts` really slower than secondary query?
- Are there any scenarios where the query_posts may be used?
- Transient not working for custom loops
- post loop causes wp_users and wp_usermeta DB queries for each users
- get_the_foo() in the loop – does it perform another query?
- How to Loop within a Loop (Display Children and then Grandchildren)
- Loop posts only excluding first post
- Custom search form to display users only
- Loop after page content
- How to get an array of years from all of the search results, and use it to filter by year the paginated loop?
- A loop with all articles with certain text strings in tags
- Display most viewed post from last 30 days is not working correctly
- Query posts if meta key starts with
- 3 Posts in Loop, Show Stickies First
- Get search.php results in header.php?
- Query reset problem or flawed code to enable custom post type query
- Query last updated posts (posts updated in the last 24 hours)
- Conditional query that displays on Woo product attribute pages
- How do I use AJAX Query in my posts loop?
- woocommerce get_price_html not pulling in correct price
- Filter the_posts doesn’t work on search page
- How to fix pagination for custom loops?
- How can I paginate this?
- How to display posts by vote count and if no value continue with latest posts with no votes?
- How to fix pagination for custom loops?
- Split wordpress loop to multiple layouts
- Making a query to the DB using same parameters of loop
- Loop inside query
- How to modify search.php to not show pages only show posts
- Include future posts in tags and in search
- get_delete_post_link() inside Loop stubbornly returns nothing
- loop inside the foreach
- Query posts only with actual text content (not including shortcode or images)
- Search page loop banner image issue
- Does search.php autofilter The Loop?
- Exclude posts based on an array
- Query post & loop problem.
- Loops for cat links not looping for wordpress site
- Custom Query with Sticky Posts
- Build a Page which shows the Oldest Post with specific Custom Field Value
- Work arounds for conditional checks inside the loop in search.php?
- Query posts and display all dates in repeater field in chronological order
- How to fix pagination for custom loops?
- Search – Check if post is a page on search page
- Get featured image outside the loop using foreach
- Alternative layout the loop
- Show posts by tags excluding current post
- Strange problem with wp_get_attachment_image_src database (db) query count
- Next 10 posts data of currently viewing post in blog page
- How to fix pagination for custom loops?
- How to fix pagination for custom loops?
- How to fix pagination for custom loops?
- Get query result before posts are displayed?
- Combine Query and Select Database to create directory loop
- WordPress loop: Display if posts exist
- wordpress showing all posts instead of date range
- Eliminate duplicates in a foreach loop [closed]
- Multiple loop with pagination in same page
- Query Loop Block: possible to restrict just child pages?
- Use Base-URL with Query-Loop
- Using Query Loop Block to list all posts under each category
- Different date time in results of search
- Getting the correct post ID in WordPress query loop
- Dinamis Query Loop template Custom Post Type dan Taxonomy di WordPress Blocks dengan PHP
- Cant pull in featured Image
- How to execute custom loop before loop content?
- Page gets displayed in post field
- Repeat code, change variable?
- Ordering Posts by parent category, name ascending
- the_content() keeps repeating itself
- Custom Looping of WordPress Posts
- Foreach loop inside foreach loop?
- Show different Google Map markers for different post_meta values
- how to place Post and page content side by side
- Add specific class to featured posts
- Adding options to loop
- Make custom WordPress comments list
- WP_Query secondary query failing
- numberposts not responding to wp_reset_postdata()
- Echo Most Recent Sticky Post in Loop?
- Template included with plugin doesn’t return all posts for custom taxonomy
- Ajax loop and history.js for SEO
- to get a little more content after ‘read more’ inside loop
- Create custom query for search?
- Show all child categories associated to post ID within loop
- Is it possible to add query parameters on the archive page?
- Remove posts_orderby filter then add it back in
- Search Functionality broken by the wp 4.2 update
- the_title() Returns the page title instead of the post
- How to include posts from one category, into a separate category of posts?
- how do i make this loop work
- Active class for my flexslider in WordPress
- Foundation modal in wordpress php loop
- Link Button url count php and wordpress