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
- Display all posts in a custom post type, grouped by a custom taxonomy
- How to use a custom post type archive as front page?
- How do you get the count of posts in an archive page?
- Display a query with multiple post types and same relationship on a single page
- How to use a custom post type as front page?
- Custom post status not working
- Display several random posts, but make sure a condition is met
- Build a content and excerpt grid loop with paging and options for # of posts
- Date archives for custom post type
- How can I add dropdown widget/box to admin post page?
- WP_Query to loop a Custom Field, Custom Post Types do not show
- Retrieving 3 latest post from each of 5 different custom post types
- Best way to style first post differently?
- List events by month
- WP_Query on custom post type not displaying, multiple loops & get_template_part
- Using new WP_Query in shortcode in a custom field causes the main post content to not display
- How to show posts from multiple post types in a single loop? And display them separately on the same template
- 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?
- Limit Authors to their Own Posts on front-end excluding admins
- Adding a span when custom post type is updated
- exclude custom post type by meta key in wp_query
- Query for posts in 2 taxonomies
- Query Custom Post by Category
- Append taxonomy terms as class names in markup?
- Display children and grandchildren of a custom post type
- How to append element after thumbnail
- How do I Use Nested Loops of Custom Post Types for MultiSite Blogs using WP_Query()
- WP_Query and using a variable for ‘cat’=> in the args array = WP Bug?
- Separate Posts and Custom Post Type in Custom Taxonomy archive template
- Impossible to get Attachments Outside WordPress?
- WP_Query search posts by custom post type and custom taxonomy
- Why does using WP_Query inside a shortcode in an elementor page cause the arguments for WP_Query to get malformed?
- Unable to get post content from custom post type loop
- Lists Posts from CPT that match the Title of the Page
- Help Structuring Query for Archive Pages
- Display custom field of specific post where post title matches variable
- Conditional to modify query results
- Loop through posts of a custom-post-type (event) and create .ics (iCal) file?
- How would I create a shortcode to display a custom post within a page or regular post?
- Output custom post shortcode. Help spot the error.
- Loop on front-page.php
- wp_query to find posts by year and month
- WP_Query is printing out only one post when posts_per_page is set to multiple
- WP Query to displaying date and posts for that date?
- GravityForm: Populate Dropdown with custom post type [closed]
- Create a random unique 6 digit number as custom field for custom post type
- Remove duplicated values from a loop
- Loading all files within a directory
- 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
- WP_Query | ‘post_type’ doesn’t work
- How to connect two custom post types with nested loops
- Filter by custom taxonomy slug on a custom post type
- Query custom post type in the loop
- Taxonomy Archive: Display only one post per term from separate custom taxonomy
- Loop through Custom Post Type, and then show children within each iteration
- Can I create a loop with multiple post types and specify different $args for each post type?
- Display CPT posts based on specific taxonomy
- What’s the difference between same wp functions get_posts(); functions in different form?
- WP_Query orderby modified to include custom meta changes
- Custom Post Type Loop throws 500 error when used in widget
- Show one item per category of a custom post type
- Two near-identical custom field types – one works, the other doesn’t . What can cause this?
- How to customize a permalink (URL) structure?
- CPT + CMB2: data not displaying for only first post in loop
- Can I list a custom post type within another custom post type in the admin area?
- How do i calculate the total of values of custom fields in custom post types?
- Custom loop with multiple taxonomy queries
- I would like to have different styles for my posts based on the content of each post
- Checking if Post Title is Unique as Loop Criteria
- Set URL link to featured image of custom post type
- Custom Tag Description unable to display just below and outside of the Loop
- AJAX load more for different custom post type loops
- On update or create post redirect to current post position in list
- I need to add endpoint for wordpress categories
- get_post_meta not working on publishing
- WordPress Custom Post Type and sort by Tags