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
- Adding ‘menu order’ column to custom post type admin screen
- Select All in Parent Category, Group by Child Category?
- Add Custom Post Type to Current Query
- Ordering posts having multiple post-meta date fields
- Get all authors with at least one post of ‘custom post type’
- Show the First Post from Each of 3 Different Post Types on a Web Page?
- functions.php conditional tag only for custom post type
- Custom Post type sort order not working in the admin area
- Order posts by (hierarchical custom) taxonomy terms and term children
- custom post type upcoming post and past post
- ascending order custom post type
- WP insert post PHP function dynamically generated Custom Fields
- Taxonomy list. Order by a specific custom post type count
- How to get only one category of custom post type?
- Adding posts of custom type into the main feed
- WooCommerce – Show orders for a specific product ? [closed]
- Inserting data into `post meta` table?
- Get random custom posts from a custom post type
- Sort posts based on multiple custom fields
- How to filter custom taxonomy categories on archive?
- Filter the content from a post globally immediately after is fetched from the database
- Combine query_posts() and get_posts() into single query
- Are there sub-systems in WordPress that would employ data structures beyond CPT that a `get_posts` won’t be able to catch?
- Shortcode for display posts on home page show only one post
- Query custom post type only if it contains another custom post type
- WordPress count child posts of each parent custom post type and use in json array for google maps jquery plugin
- How to modify archive query with pre_get_posts to append CPTs?
- convert custom query to wp_query
- How to set order for a custom post type
- Get parse_query filter to return slug instead of id
- Order posts by custom field DATE value
- creat filter with wp_query
- How to do WP_Query with two meta fields with orderby clause
- Display latest x posts from all categories in Custom Post Type/Taxonomy
- How to organise this data within WordPress
- Custom post type posts don’t show in archive widget
- Showing specific post in order of array wp_query
- Adding custom field values to wp_list_pages
- Custom post type sorting: alphabetical order
- Can I query posts by taxonomy conditionally based on post type?
- How to conditionally add Custom Post Type to Front Page
- Query not work for current taxonomy
- custom hierarchical taxonomy and custom post type list contains surplus posts
- Break up posts per page in two sections
- 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
- Post ordering not working with custom field
- Function to limit number of custom post types on homepage – TwentyTen
- Custom types, taxonomies and query optimization
- Can’t pull posts of a Custom Post Type based on the custom taxonomy of the CPT
- Query custom posts from custom taxonomy
- Query custom posts of logged in user only
- Add custom post type to query
- How to query custom post types with multiple keys?
- Orderby meta_key/meta_value not displaying anything, am I overlooking anything?
- WP Query from two Custom Post type fields as statement
- Get_post_custom not fetching value from array wordpress
- Display Parent-Child Posts in specific order by comparing IDs in array
- I’m having trouble with Related Product “tax_query” ‘terms’ value
- Using OR relation in meta_query to check for a value before sorting by another
- Order posts alphabetically with numbers but some of the posts has numbers in the title
- How to order taxonomy terms by most recent post?
- Get all posts by many custom post types
- Creating a custom WP query for a Custom Post Type
- SEARCH QUERIES – REVERSE OUTPUT
- How to order multiple custom post types with same taxonomy by date
- post type => ‘any’ not applied my custom queries
- Using Orderby and meta_value to order natural/alphanumerical
- Posts show up under “published” but not “all”
- How do I display specific custom posts, and how do I edit a post’s singular page?
- How can you use a page for a custom post type?
- pagination for a custom query
- WordPress get all post with like in terms [duplicate]
- WP Query with multiple post types ordered by custom meta date then published date
- Custom post order when using OR relation
- show previous/next post orderer by title in custom post types
- How can I give WordPress child custom post type the same title and slug as its parent?
- Query child posts on parents single.php?
- WordPress can only query up to 766
- How would I get a list of posts from a custom post type
- WordPress search results
- How to add post type in masonry posts elementory widget
- Create a list of months based posts
- WP_query orderby not working after WP4.0 update [closed]
- How do I correctly query posts from a post ID?
- WordPress Admin Page Slow. Customer Post Type is the slowest
- Add a class to a menu item depending on a body class