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
- what are the numbers between curly brackets in search query
- How to place comments_template(); outside the loop?
- How do I create a meta box for dates?
- Hook into the loop via a plugin, and output something after every X post?
- Custom Query to search through categories
- How to sort posts in archive loop
- Show top level comments ordered by number of replies
- Redirect Loop to Page, Can’t Find Origin, Can’t Remove [closed]
- Post Format single-loop.php using get_template_part
- Varying Search Result Pages
- How to show “teaser” posts on blog / archive pages, otherwise full posts
- Genesis multiple category custom loop 404s after first page
- Shortcode in posts called by ajax is not working
- Problem getting current post tags to show in a widget
- Include multiple page ids in loop
- How to conditionally add Custom Post Type to Front Page
- For each loop on every word in post
- Display name of taxonomy once
- Displaying the first, second, and third posts from a category in separate slides
- How to insert Collate into WordPress search query?
- How to use this $tax_selection variable in this custom loop?
- Display all categories as plain text
- Changing WordPress sort order for returned child pages
- Show Posts via cat+cat in URL that are in both Categories doesn’t work
- Get gallery in loop through ajax
- Pagination on a underscore custom theme
- Get top Page IDs from menu and cycle through their child pages on a scroller
- How to show terms from another taxonomy
- The Loop isn’t working
- the loop – how to control whether wp or plug-in runs it
- stuck with template hierarchy
- How to create an identical second loop for attachments?