You can add a php variable and increment it every time the while loop runs
$args = array(
'post_type' => 'events',
'order' => 'ASC',
);
$wp_query = new WP_Query($args);
?>
<script type="application/ld+json">
{
"@context":"http://schema.org",
"@type":"ItemList",
"itemListElement":[
<?php
$i=0;
while ( have_posts() ) : the_post();
$i++; ?>
{
"@type":"ListItem",
"position":"<?php echo $i; ?>",
"url":"<?php the_permalink(); ?>"
},
<?php endwhile; ?>
]
}
</script>
Related Posts:
- Custom post type loops with different page templates
- How do you output custom code between posts in the loop?
- Very Slow Page – How to Optimize # of Queries?
- How to make sure content doesn’t display if selection is empty
- Configuring a meta query with multiple post types that have the same relationship on a single page
- How can I group posts by months and years?
- Using wp_query to modify the loop in index.php for a CPT
- Using Wp_Query, Json to add Highcharts series data
- foreach loop inside the loop creating duplicates in output
- Foreach loop returning more than one item when querying taxonomy
- Page that lists publications by classifying them by taxonomy
- set object terms after some some time of published post – functions.php
- Pagination not working in custom post type. Help
- subtracting the current post form then whole loop, which is generating all CPT titles
- WordPress loop add heading before first of type
- How to make a shortcode for my WP_Query Loop? [duplicate]
- Strange behavior on WP_query
- get_post_meta for Custom Post Type ( CPT )
- Query Custom Post Type by Tag
- List events by month
- WP_Query on custom post type not displaying, multiple loops & get_template_part
- How to create posts (not post template) to be displayed on projects page?
- WP_Query post at custom position
- Should unaltered default loop/query return a list of custom posts belonging to a custom taxonomy?
- Adding a span when custom post type is updated
- Query for posts in 2 taxonomies
- How do I Use Nested Loops of Custom Post Types for MultiSite Blogs using WP_Query()
- Impossible to get Attachments Outside WordPress?
- Help Structuring Query for Archive Pages
- Output custom post shortcode. Help spot the error.
- Loop on front-page.php
- wp_query to find posts by year and month
- Custom Post Type Taxonomies -Posts not showing in Category or Tag pages
- Custom Post Type Loop within Shortcode
- A good strategy to print custom posts (offer) that are checked inside the metabox of a post?
- Can’t get order_by meta_value_num to work properly
- Query custom post type in the loop
- Display CPT posts based on specific taxonomy
- CPT + CMB2: data not displaying for only first post in loop
- How do i calculate the total of values of custom fields in custom post types?
- get_post_meta not working on publishing
- ACF field key/value to show on taxonomy list
- WP Query with categories only shows one post and ignores the category
- Different Category system needed for the Custom Post Type
- Wrapping x posts in html without leaving empty html
- WP Query post__in not returning correct results
- Sort posts in loop by the WooCommerce Membership of the author
- WP_Query Custom Post Type if Category ID Equals
- Assign category a default post type
- How to use a variable as a function name?
- get_pagination not working on a custom post type query (using WP_Query)
- WP_Query with custom post type ID
- Having Issue on Ordering CPT by Custom Field In Custom WP Query
- Different options per post type in WP_Query
- Get data from PHP to JavaScript to set position of each post on front page
- Removing full title and breadcrumb header container for a specific post type
- display posts of custom post type with custom taxonomy
- Custom Ratings for Theme, Proper way to Refactor Code and Clean up Template File
- postsperpage value not being applied
- Display the current post in browser as the first post in a loop (for a slideshow)
- Function to erase every post from a taxonomy
- How to retrive Custom Post Type Meta Fields in Custom WP_Query
- How to fetch posts that are stored in the different table than (default) wp_posts?
- Cant’ Display Custom Post Type Title Base on Tax Terms
- What is the most efficient way to execute recursive complex queries?
- redirect after submiting post for review
- Get Posts List of Current Selected Custom Taxonomy in Shortcode
- CPT loop doesn’t seem to account for post date?
- update custom taxonomy custom fields
- Alike Shortcode using in Custom Shortcode
- Sort custom post column by generated value?
- Pagination Not Working When Used With WP_Query() `offset` Property
- Custom meta fields not showing up in WP_Response Object via custom endpoint
- Tell wordpress to show a single page instead of an archive page
- Search result based on URL
- Wrapping an unknown amount of posts inside separate HTML Containers during WP_Query loop
- Change Search display for Custom Post Type
- Stored meta from attachment, video length?
- sorting in wp query based on custom field value
- Custom post Query and WordPress Post Query Clash
- Add active class to foundation 6 tabs while looping categories
- Duplicate posts in my custom loop
- Only show current category post
- WordPress query posts by custom post type not workng
- Featured image in custom post is being disabled
- Is it possible to add query parameters on the archive page?
- Function not pulling image or text from custom post type
- How can I pull information from my loop and divide them seperately?
- WordPress multi-query not returning as expected
- Fallback if statement based on the number filtered from it
- Custom Post-type not returning the right child_of
- Looping taxonomy in taxonomy?
- Fourth page of custom post type archive page does not exist
- Catergory args causing loop not to show
- Add HTML before a specific div?
- How do I filter a custom post type loop by a field?
- How to manage wordpress knowledge base/wiki/posts collections
- add_rewrite_rule not working with custom post type
- How can I show posts with the same tag?
- How do I exclude the current post from the upcoming post query