I think you need to read up a bit on how The Loop works in WordPress:
https://codex.wordpress.org/The_Loop
And how the WP_Query class:
https://codex.wordpress.org/Class_Reference/WP_Query
I am assuming your only want 2 loops, at the moment your have 3.
-
On line 19, which stores its posts in a var $query then does nothing.
-
On line 21, which is your main unaltered loop.
-
On line 54, which your colleague helps you with? Seems to be working.
So what you need to do is pass the arguments from your first loop to your second loop instead.
You can do this by making a new WP_Query like you did on line 53.
$query = get_posts( $args ); // line 19
becomes:
$query = new WP_Query( $args );
and Loop through the results using the have_posts() function.
if( $query->have_posts() ) : while( $query->have_posts() ) : $query->the_post(); // line 21
Related Posts:
- Get the ID of the latest post
- Custom Post Type order by modified date and custom meta field issue
- Number of posts in the archive
- Custom query for custom post_type
- Changing WordPress sort order for returned child pages
- Custom post type order by post_title
- Show first posts with custom field not empty and order all by title
- Allow admin to determine the order of queries?
- Posts 2 Posts: query connected — orderby problem
- Order custom post type is beign ignored
- How can I show a field ID in Elementor with Request Parameter
- WP_Query orderby and tax_query
- I am trying to hide a custom post type category to logged in users with Pre_Get_Posts
- Displaying Posts from Custom Post Types
- Different Ways to Query Custom Post Types?
- Ordering custom post type by multiple custom fields
- How to organise this data within WordPress
- Manage Columns : order by post_parent’s title
- Order by custom field meta_key date and then by custom file meta_key number
- Custom post type posts don’t show in archive widget
- Showing specific post in order of array wp_query
- Reworking function for counting custom post type posts count
- Archive not sorting correctly
- 4 column-loop ordered alphabetically with entries grouped (and labeled) by their first letter
- Get only used meta_values
- Ascending Order is not Working in Custom Post Type Listining
- Add a custom meta box for client to order CPT posts how they want
- Query of custom post types only shows first post
- Adding custom field values to wp_list_pages
- Query multiple taxonomies with pre get posts
- How to query 2 custom post types that need to share a slug?
- Recoverable Fatal Error – Object of class WP_Post could not be converted to string
- Custom post type sorting: alphabetical order
- Query Custom Post Types with checkboxes
- WP_Query() with custom post type and taxonomy — get all terms?
- show all custom posts types in home page
- List of child custom post types lists all custom post types
- $wpdb->get_col and ORDER BY?
- Query custom post type based on post id and custom field value
- populate array with posts
- Listing custom post types on archive page with array
- How to Make infinite loop of post
- Make (custom) post type accessible only by custom query
- get_posts seems to be skipping the last Post
- Displaying multiple post types on home page
- Can I query posts by taxonomy conditionally based on post type?
- Conflict between wp_list_pages and get_posts – list pages not displaying
- How to conditionally add Custom Post Type to Front Page
- Having Issue on Ordering CPT by Custom Field In Custom WP Query
- Graphql: Unable to query (where:{author}) for custom post type
- Return number of all custom posts type by author in all statuses
- WP_Query of custom post type sorted by meta_key has unexpected results
- Query not work for current taxonomy
- Display a post from custom post type only if all the selected taxonomies and custom field value matches the record
- Returning a custom content types with meta values
- Is it possible to use array_walk() to append terms to an array of posts?
- WP_Query not resetting after wp_reset_postdata
- custom hierarchical taxonomy and custom post type list contains surplus posts
- Custom Query: If One Post Object Field Value Is The Same As Another
- Break up posts per page in two sections
- Custom Post Type not showing in main loop
- Custom Post Type setup
- new WP_query > displays posts only once instead of running through full array
- Pagination on search results page
- Querying a custom post type, but not show duplicates
- Shortcode to return single custom post based on post taxonomy
- is_main_query() never called on WP 4.4
- Group by custom field value (start and end times)
- meta query not retrieving posts
- Hide text if query has no posts
- How do I get the index for a custom post?
- Getting custom post types to properly display alphabetically
- Create query for both custom post type and category
- Filtering custom posts by custom fields (ACF) [closed]
- How to get custom post type title, excerpt, thumbnail and permalink by post ID?
- Post ordering not working with custom field
- Function to limit number of custom post types on homepage – TwentyTen
- Get posts by category name
- Filtered by a custom field, ordered by another
- orderby parameter not working in custom query
- Why the_excerpt() function returns excerpt on the Home page and trimmed content in sidebar?
- Custom taxonomy query showing more than 4 posts
- Custom types, taxonomies and query optimization
- Adding Page Ordering to a Custom Page Type
- How to properly use Categories with Custom Post Types
- Can’t pull posts of a Custom Post Type based on the custom taxonomy of the CPT
- Query Custom Post by taxonomy multiple categories
- 4 posts per page from single category
- Query custom posts from custom taxonomy
- Custom Post type showing up in loop, regular posts are not showing up
- All in one calendar custom post type query doesnt work as expected
- Displaying Portfolio Filter by Category Order (alphabetically)
- Query custom posts of logged in user only
- show most viewed posts of last days by link?
- Display a random customposttype2 excerpt in single-custompostype1.php that shares same taxonomy
- Getting the list of the latests posts and custom type posts in the homepage
- Add custom post type to query
- How to query custom post types with multiple keys?
- Is there a (preferable built-in) way to check what custom queries are used in a theme?
- date_query empty results with custom post type