Yes that would be easy. You can use the get_the_permalink()
function to retrieve a post’s link. Here’s how to do it:
// You are storing the post data here
$posts_arr[] = $post;
// Add the URL to the same array element
$posts_arr[]['url'] = get_the_permalink();
You can get the index of the current post in the loop by using the $query->current_post
method, so I suggest you use that as the key of your array:
// You are storing the post data here
$posts_arr[ $query->current_post ] = $post;
// Add the URL to the same array element
$posts_arr[ $query->current_post ]['url'] = get_the_permalink();
Related Posts:
- Is there a JavaScript API? How to access public and private data in JS?
- Nonces, AJAX, script variables & security in WordPress
- How do I query posts by a sub value with the API?
- Why is wp_localize_script returning false?
- Is there a better way to access transients using javascript
- Get localize of a loaded javascript
- How to Object.freeze wp_localize_script
- jQuery AJAX cross domain
- Can JavaScript connect with MySQL?
- SyntaxError: JSON.parse: unexpected character at line 1 column 1 of the JSON data
- JavaScript implementation of Gzip
- ASP.NET MVC controller actions that return JSON or partial html
- How to cache json with wp-super cache
- Allowing admin-ajax.php to receive “application/json” instead of “x-www-form-urlencoded”
- gettext does not translate when called in ajax
- How to HTML5 FormData Ajax
- Custom PHP endpoint for a plugin’s AJAX call
- Refused to execute script from ‘***’ because its MIME type (‘text/html’) is not executable, and strict MIME type checking is enabled
- WordPress Ajax Login without page reload
- jQuery Autocomplete not working with wp_localize_script
- Drag and drop multiple file upload using Ajax WordPress
- Changing the entire control choices using wp.customize with JavaScript
- Vue.js + AJAX Shortcode
- Turn jQuery.ajax() request into XMLHttpRequest (vanilla JavaScript)
- Can’t seem to get wp_localize_script to work
- WP REST API route request explain
- How to use wp_send_json_error?
- admin-ajax.php HTTP400: BAD REQUEST – The request could not be processed by the server due to invalid syntax
- WordPress AJAX calls not detecting language properly?
- AJAX issue – Uncaught SyntaxError when processing Zip File
- WordPress AJAX Call Not Return Result
- Extending wp JavaScript base class to make a post request to a custom REST endpoint
- How to localized one js file for different actions?
- Does wp_localize_script call a Javascript Function or Simply Pass PHP Parameters to It
- wp-admin AJAX with Fetch API is done without user
- Admin Ajax and HTML5 Formdata
- Call javascript function when category was added via ajax
- Populating content dynamically via AJAX and Advanced Custom Fields [closed]
- Woocommerce Ajax Add cart not working
- json encode not work in wordpress
- Populate a Map at The Same Time as showing Posts via AJAX
- wp_localize_script not working on ajax response
- Script Localization doesn’t work
- Creating a Multi-Level Associative Object Using AJAX
- Show Post Content with AJAX
- Load JavaScript from a post that’s loading into Fancybox via ajax
- Ajax random number always the same
- Admin-Ajax Error
- How to register javascript variables in wp_localize_script?
- Cache wp-json/posts without a plugin?
- Gravity Forms closes my popup on Validation Error [closed]
- How to add ajax url to js using wp_add_inline_script()?
- Localize script not working
- Upload data from weather station to WordPress Website
- How to disable drag-and-drop upload function in Media Library?
- javascript ajax and nonce
- How can I wp_send_json data?
- Full Front End, AJAX comment system and comment reply script
- Making POST request with AJAX returns a 400 error (without jQuery)
- Chained ajax call, second call returns 0
- Run javascript upon successfully set featured image
- Ajax page load without reload
- How to load dynamic option with ajax
- Get uploaded attachment width & height and attachment ID after upload them
- Why the wp_localize_script() does not work correct in my case? ( /wp-admin/admin-ajax.php 400 (Bad Request) )
- Updating failed. The response is not a valid JSON response. specific to my browser when I include javascript in my html
- Uncaught TypeError: Cannot read properties of undefined (reading ‘message’) [closed]
- Refresh checkout fields on add to cart with order bump
- Refresh Gutenberg with JS for it show updated post
- javascript onClick update user_meta from jquery.ajax
- how to make sure js is enabled before executing php function
- ERROR while passing data from JS to PHP via AJAX
- Ajax is not defined
- React to AJAX adding to the page
- Download doccument on server rather than clients browser
- Using existing ajax data that is loaded into page
- Ajax call works for logged in users and returns “Bad Request” for guests [duplicate]
- Ajax call from Plugin using Class
- How to safely pass post_id and user_id via AJAX to the backend (prevent user from changing it via JS)?
- How to inject data content from external json into a modal, using UIkit?
- AJAX form not working, still reloads on submit
- Get post details with pure javascript ajax
- WorddPress website admin part not working correctly – I think ajax/json issue
- 403 error for ajax POST request
- Jquery wrap permalink in a data-attribute?
- WordPress Ajax JSON success return no being recognized
- Session variables lost during Ajax calls – WordPress – Sage Starter Theme
- AJAX Call in Plugin Returns More than JSON
- ‘Dehighlighting’ navigation once clicked
- wp_localize_script not create variable in head section
- Bad Request when adding new post via ajax form
- AJAX admin Internal 500 error Failed to Upload
- Using Javascript Callback from plugin in a theme
- Pass a PHP variable (loop-audio.php) to jQuery function (js/script.js)
- WordPress wp_localize_script nonce and ajax URL
- WordPress Ajax send response on every iteration of a loop
- Import js variables loaded via wp_localize_script() into js module without global scope connection
- Bad Request 400… jQuery ajax post of json data to wordpress admin-ajax.php
- Escaping admin_url output being passed to js (esc_js vs esc_url)
- How to submit a button automatically after every scheduled hours?