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 UI Autocomplete/Autosuggest WordPress
- How to show custom fields in modal in category page
- jQuery AJAX cross domain
- React Js: Uncaught (in promise) SyntaxError: Unexpected token < in JSON at position 0
- Can JavaScript connect with MySQL?
- JSON.parse() not working
- 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
- “NS_ERROR_DOM_BAD_URI: Access to restricted URI denied”
- How to cache json with wp-super cache
- Why use wp_send_json() over echo json_encode()?
- Allowing admin-ajax.php to receive “application/json” instead of “x-www-form-urlencoded”
- gettext does not translate when called in ajax
- Can’t get a JSON object in response to an Ajax request with wp_ajax
- How to HTML5 FormData Ajax
- WordPress function that makes HTML safe to be sent via AJAX request
- How to properly use wp.ajax.post?
- Custom PHP endpoint for a plugin’s AJAX call
- wp_localize_script $handle
- 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
- Dynamically changing navigation links (next and previous) via AJAX
- 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
- Quick Edit: Selected Custom Taxonomy Not Refreshing After Save
- Vue.js + AJAX Shortcode
- Turn jQuery.ajax() request into XMLHttpRequest (vanilla JavaScript)
- Can’t seem to get wp_localize_script to work
- How to Use JSON With AJAX?
- WP REST API route request explain
- fetching via fetch/ajax gutenberg block data from third party
- ajax and nonce when JavaScript is in a seperate file
- 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
- How to localize inline script called with ajax
- 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?
- Ajaxing in functions.php
- 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
- Most performant way of fetching remote API data?
- Admin Ajax and HTML5 Formdata
- Call javascript function when category was added via ajax
- Populating content dynamically via AJAX and Advanced Custom Fields [closed]
- Help with AJAX front end comment moderation
- Woocommerce Ajax Add cart not working
- json encode not work in wordpress
- how to send Ajax request in wordpress backend
- Unable to parse JSON response from wp_send_json_success [closed]
- Populate a Map at The Same Time as showing Posts via AJAX
- wp_localize_script not working on ajax response
- Ajax Modal Flickers When Opened Multiple Times
- 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
- splitting the URL using jQuery
- AJAX Load more on CPT returning random posts
- Ajax random number always the same
- How to make tabulator ajax call in wordpress?
- Refresh Markercluster after ajax call
- Admin-Ajax Error
- Ajax store response json in variables
- How to register javascript variables in wp_localize_script?
- Making an ajax request from a different domain
- Performance optimization of tree like structure
- Cache wp-json/posts without a plugin?
- Radio buttons live refresh in the customizer
- Gravity Forms closes my popup on Validation Error [closed]
- Ajax call with javascript in post content (not enqueued)
- How to add ajax url to js using wp_add_inline_script()?
- Using wp_localize_script to get data from cpt and pass it to maplace-js locations
- merge wp rest api query to get posts per category does not work
- Retrieve JSON file from JS trough php
- Localize script not working
- Using admin-ajax prevents regular php form submission
- Upload data from weather station to WordPress Website
- Sql formatting for post data within function
- wp_mail doesn’t work when logged in?
- Hide Load more Ajax button if there is no more users to load or less than the number?
- 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)
- Send checkbox status with Ajax / JSON and save it
- Chained ajax call, second call returns 0
- WordPress Ajax Filter