You’re right you should be using an id.
I would use a counter in conjunction with get_the_ID();
$arr_posts = new WP_Query( $args );
if ( $arr_posts->have_posts() ) :
$index = 0;
while ( $arr_posts->have_posts() ) : $arr_posts->the_post();
echo $index . '_' . get_the_ID();
endwhile;
endif;
This will give you a unique id which you can use for each item in the loop.
WordPress has a the $index variable built in. We could rewrite this as:
$arr_posts = new WP_Query( $args );
if ( $arr_posts->have_posts() ) :
while ( $arr_posts->have_posts() ) : $arr_posts->the_post();
echo $arr_posts->current_post . '_' . get_the_ID();
endwhile;
endif;
Related Posts:
- Modal won’t appear on all pages
- How to make async query in wordpress?
- How to add new ACF repeater row after removing all rows using jQuery/Javascript
- onclick not working since move from HTML to WP
- How to set javascript options for select2 in PHP array of plugin
- create timestamp links to jump to specific times on rumble videos
- Putting custom html/js page into Elementor as it’s own block
- Add Paypal button redirect to a specific page after completing
- Multiple jQuery inputs or binds in Customizer Control Javascripts
- Form will not popup, when clicking on the link to the form
- wp post_tag change minlength
- How to get file object from file_attachment?
- How to load Javascript code or functions.php later in a child theme?
- google pie chart in wordpress
- How to locate the js code and php code for certain function?
- How to validate image with specific height and width selection in media selector
- How to change the link address from internal to external
- How do you create your own link preview for my website?
- Can’t get rid of JQMIGRATE: Migrate is installed, version 3.3.2. Manually updated all the libralies and site. 5.8.2
- how to add a custom javascript file to our theme
- Script only works on wordpress home page & only when Jqurery is aded using
- how to prevent added meta box from being injected with style=”position: fixed; top: 56px;” at scroll down
- I want to make a post api call once a post or page is published/updated and show a javascript alert box saying ‘Post has been published/updated’
- download svg to png size image
- Query filter by value in meta_value array
- Add a Page Screen is Visually Blank
- Taxonomy Template displaying different color post tag js
- Problem with revisions only returning four results
- Debugging JS errors
- Check if user can in javascript
- Javascript File Does Not Work
- JS inside modal doesn’t work
- How to Get Post Meta in .Js File [duplicate]
- My code will not execute in wordpress, even though I’ve been told the code is fine
- Drag-to-Scroll Landingpage
- wp-api Backbone JS Client fetch options
- How to display different content on the same page using different URLS
- Easiest way to find JS conflicts
- Save in localstorage and db and show it later
- Web cover page open when button clicked
- internal anchor links no longer working after upgrade
- Deferring Script wp-i18n causes a console error ‘wp is not defined’ – Gravityforms
- Need help in fixing javascript in WordPress
- How to run Javascript popup modal in a loop?
- How do I load urls from an external .js file to my admin head?
- Generating dynamically Schema LD+JSON microdata with Javascript works in test environment but not in WP
- Why does my array sort order changes when I pass it to JS using WP_REST_Response?
- Add JavaScript-Library “Fitty” to WordPress
- Change (replace) tags to tags
- WordPress Guternberg Content For React Native
- Always render emoji with twemoji.js – not system emoji
- Enqueued script fails
- Including dependencies using @wordpress/dependency-extraction-webpack-plugin
- Open href in a new window with onclick
- Defer Parsing of “createjs.min.js” not working
- Google Tag Manager only load when connected to Admin
- Rest API and how to deal with it in server side
- Gutenberg sidebar show input field on toggle
- Script Loaded in WordPress but won’t run
- Darkmode Custom CSS Toggler – Uncaught TypeError
- Change background video when scrolling reaches a certain ID
- Get the ID of a page in Parent combobox in editor
- Link to Lightbox Image-Group from Menu?
- How do you change the text “Update failed. You are probably offline.”
- Uncaught TypeError: r is not a function
- How to show cities according to the state in Form using Javascript? [closed]
- Replace script attr or link
- Nothing in dashboard that uses javascript works
- on change form submit variable value not updating
- Access checks with custom REST endpoints and backbone
- Insert HTML markup to page content from the Media Frame modal
- Uncaught TypeError: Cannot read property ‘add’ of undefined bp-plupload.min.js
- “jQuery Not Defined” Error When Connecting to PayPal
- Fade-in Fade-out doesn’t work in WordPress
- Contact Form 7 Conditional redirect
- How to handle wordpress sso authentication with gatsby js?
- Error on clicking ‘Screen Options’ tab only at Products-related editor screen(s) and for specific user
- Is it possible to override only a part of another plugin’s / theme’s js (asset) file?
- script not working anymore after saving widget settings
- java console error about touch navigation
- Development desktop/responsive
- Google Page Speed
- Can’t Listen to KeyDown in TInyMCE Iframe (jQuery) and Pass it to Parent HTML FORM
- Can I get the user name in JavaScript?
- Issue migrating a checkbox-type meta field to the block editor
- WordPress query: merge meta key (number) values and sort
- Remove escape characters from JSON string pulled from a database
- How to pass data to javascript in custom widget class
- ACF values to Script with auto refresh
- youtube full screen on off permater code help for wordpress
- Console Messages: A cookie associated with a cross-site resource at
- Select parent from child class name then add another class name to the parent
- Setting wp_enqueue_script correctly
- [Vue warn]: Error in render: “TypeError: Cannot read property ‘wp:featuredmedia’ of undefined – REST API
- When adding google tag script in website, functionality not working
- The script works only once by clicking on the opening and closing
- Is it feasible to call angular’s page from wordpress website?
- Update block once an API request returns with a value
- Gutenberg – dynamically created element: how to set onChange?
- JSX SVG Icon with WordPress