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
- Jquery Slider for profile template
- Get excerpt using get_the_excerpt outside a loop
- wp_list_categories: get latest featured_image of category
- WordPress Alphabetical Glossary close div in loop
- Page template not displaying
- How to get_template_part using AJAX?
- How can I modify the loop from a plugin without wiping out other filters?
- Loop in Related Posts WordPress
- How to order by multiple fields using standard query_posts?
- How to overwrite orderby with add_query_var
- How to query two meta fields and display results between them
- How to display first post
- Pagination on custom post type on front-page.php
- get_template_part() Not Working in Loop
- CPT while loop not working
- Problem with Front-Page.php loading recent posts
- Comments_template doesn’t work
- Get markup for post without loading into the template
- How to synchronize The Loop with the max post per page?
- How to add a byline to all the pages?
- Displaying member join date on page
- Ascending order has strange effects on wordpress loop
- get post images to link to external sources
- Build A Custom SQL Query for WordPress Search
- Custom loop not working in singular.php, working in other pages
- Loop Posts Outside of WordPress Installation
- How to include posts from one category, into a separate category of posts?
- how do i make this loop work
- Making a specific page wordpress compatable that is not index
- display only parent replies count in index.php
- Tag custom loop show posts
- While loop inside another while loop
- loop mix my child-category and parent-category
- Insert multiple custom components after x-number of posts