Problem: I'm using a 3rd-party JavaScript plugin that requires access to the IDs of the first 5 results in a custom search View. How can I access the result post IDs in JavaScript?
Solution: Add the post ID to the markup of each item in the Loop as a data attribute, then use jQuery.each() to loop over the results and obtain that information. Trigger this code on document ready for non-AJAX Views, or use the Frontend Events button to trigger it on pagination and search events.
Relevant Documentation:
@https://api.jquery.com/jquery.each/
This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.
Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.
Sun | Mon | Tue | Wed | Thu | Fri | Sat |
---|---|---|---|---|---|---|
8:00 – 12:00 | 8:00 – 12:00 | 8:00 – 12:00 | 8:00 – 12:00 | 8:00 – 12:00 | - | - |
13:00 – 17:00 | 13:00 – 17:00 | 13:00 – 17:00 | 13:00 – 17:00 | 13:00 – 17:00 | - | - |
Supporter timezone: America/New_York (GMT-04:00)
This topic contains 2 replies, has 2 voices.
Last updated by 6 years, 6 months ago.
Assisted by: Christian Cox.