I don’t have a full detailed response for you, but here’s a few things I’d suggest:
1) Use template parts for each of those segments. That will help clean up the template so it’s easier to work with in the future. ( see here: https://konstantin.blog/2013/get_template_part/ )
2) You could then create a helper function for the entire query, basically get EVERYTHING, then have login in the helper function to filter the results. So that within each new template part you’d have something like this:
prefix_index_query($posts_per_page = 3, $post_status="publish")
See here: https://tommcfarlin.com/wordpress-helper-functions-for-templates/
Those two things alone will get you going in the right direction for a much cleaner file structure.
Related Posts:
- Different ‘posts_per_page’ setting for first, and rest of the paginated pages?
- How to adjust found_posts so that it accounts for offset and pagination
- WP Query with offset breaks wp_pagenavi or any pagination
- Exclude first 5 posts of specific categories in the main loop
- Custom query, works, but I get a “Notice: Undefined offset: 0…”
- Offset Page Loops and Pagination
- Storing query variable and then using wp_reset_query
- While creating Block Themes in WordPress, how can I query custom posts for an Archive view?
- How to use offset in WP_Query
- How can I fix: “Notice: Undefined offset: 0”?
- WP_Query, pre_get_posts and offset
- Why does get_posts only show results for Admins or logged-out users?
- WP_Query with offset and ‘orderby’ => ‘rand’, offset not working
- How do I rewrite this loop as a new WP_Query style-loop?
- WP_Query arguments order
- WP_Query – Adding “offset” posts to the end of the loop
- Stomping WP_Query in author archive to facilitate pagination with custom queries
- Apply query arguments after the nth post
- AJAX Breaking Offset Argument In WP Query
- Page navigation doesn’t seem to work when I add offset?
- WP_Query offset is returning post from prevois loop
- Need help understanding this WP Query [closed]
- Offset WP_Query by negative 1
- WP_Query Orderby meta_key and hide some meta_key
- setting offset to category number in archive page
- Featured Image as Background with Offset
- WordPress WP_Query offset parameter not working with search parameter
- Multiple homepage layouts as selected by user from theme options
- wp query problem
- Multiple WP_Query with pagination shows Page/2 content on the remaining pages
- query loop “inherit query from template” prevents setting sort order
- Find out total number of pages in global query on archive page?
- Resetting post data to previous loop in nested loops
- Order by multiple meta key and meta value [closed]
- Is it possible to completely stop WP_Query retrieving posts?
- Pagination returns 404 after page 20
- Make a WP Query search match exactly the search term
- Make loop display posts by alphabetical order
- Displaying several specific pages using WP_Query()
- WP-CLI How to generate a list of posts with corresponding meta values
- Query to return maximum of one post per author
- Get attachment by slug
- Warning: urlencode() expects parameter 1 to be string, array given
- Group posts by custom field
- How to get the posts published in last two days using WP_Query?
- getting posts and number by specific meta value in multiple meta
- All sticky posts are returned in custom query
- Get attached media only
- Can not switch the queried post in pre_get_posts hook
- how to fire join query with post_meta
- Why use JSON API to display recent posts?
- Pagination problem after WP_Query with tag filtering
- Custom Loop in Page Admin Causing Other Fields to Fail
- Pagination stops at page 6
- How to limit total number of posts in wp query loop?
- Get list of terms that have posts in another term
- WP_Query with Metavalue
- How to vary post loop results layout and resume?
- Using Ajax to load more posts | Help me change the wording on my button to notify the user
- Adding an array from a query string to a WP meta_query
- WordPress add_rewrite_rule() cannot visit lower url levels
- Get a post from other loop each n-posts in the main loop
- Sort by price woocommerce by ID post_meta
- Retrieve posts using thumbnail id as meta key
- Need to convert string of term ids into comma separated integers for use in an arguments array
- How can I allow sticky posts but cap the query to 1 post?
- How do I get my custom query to work with search results after the first page?
- Need Sub-category with main Category
- Easy way to write complex queries in wordpress
- Error with function in functions.php?
- I am having problem sorting custom post type using WP_Query
- WP_Query and is_page_template() conditional
- difference between querying database and using the loop
- How to do logical OR in terms in WP Query?
- Slow Query On Search
- Child pages not affected by orderby
- Write WP Query that selects posts that are part of the same two categories
- Error in meta_query not get result
- Custom wp_query – I’m getting ‘all’ post, not the specific post in the query
- Phpmyadmin – post editing
- wp Query Posts to display in Nivo Slider
- Query not sorting DESC
- Prioritising and Ordering Posts By Category Name Using A Custom Loop
- Filter products on category AND tag
- meta_query – check for multiple meta values in key which holds an array of values
- How to sort wordpress posts already selected by WP_QUERY
- Searching for a specific month in a metadata saved as Timestamp (Wp_Query)
- SEARCH QUERY PLEASE HELP | call_user_func_array() expects parameter 1 to be a valid callback php
- Set “editor” role to existing user
- how to get wp_query posts only first letter of alphabet A?
- Custom Post Type WP_Query with filters and search
- Merge wp-query and get_users
- WP_Query how to add a thumbnail to the first post from the last 5 posts?
- Query by meta value (add a dropdown of all values)
- Why is $wp_query fetching nothing?
- How to query post into a complex slider
- WP_Query Sorting Posts by month … timeline effect
- My class function is not seeing GET url paramaters
- how do i remove plusone js from WP? [closed]
- How to use wp-query to search for posts where post_content OR post_title OR post_name