You’d only use the REST API or AJAX if you didn’t know what data you needed until the script was run or there was some user interaction. If you already know the data you need based on page you’re on then you might as just pass that data with wp_localize_script()
, otherwise you’re forcing the client to make a separate request once the page has loaded, slowing everything down.
Related Posts:
- How to localize value of posts
- WordPress Rest API only returns content when posttype has editor capability
- Very simple wordpress block to display posts from an api call
- Using wp_localize_script to get data from cpt and pass it to maplace-js locations
- URL issue retrieving Custom Post Types using Backbone JS API
- How to make sure, that only the selected post is changing?
- Load more post with AJAX
- Post current post type to my Ajax
- Ajax load more post button not showing
- Open div inside a custom post-type with Fancybox
- Add custom parameter to REST API request of a custom post type?
- Custom Taxonomy Invalid in REST API
- How to get the parent of a non-hierarchical custom post type being edited in Gutenberg
- How do I get the intended post type of a revision post?
- Using The REST API How To Pull All Custom Posts?
- Storing posts from query and accessing later via AJAX call
- Push metadata in array
- Cannot add custom field to “orderby” parameter in Rest API
- Getting meta in editor plugin, and event triggering issue
- Save the post parent in a custom post type in Gutenberg
- Plugin – Combine Meta Box Input Fields into single saveble record
- Expose a custom field of a custom post type to the REST API
- How to create custom post by using REST API securely?
- Custom post type archive page – Posts overview – with one modal for multiple posts?
- JS innerhtml changing style when using AJAX
- WP Rest API – How to get an empty response if query has no posts
- Callback to custom field is not working in WordPress REST API
- Custom Post Type not showing in Rest API on Multisite
- Side effects of Script and Iframe in post
- post meta parameter in post custom-post-type endpoint with restapi
- Exclude objects from WordPress API based from ACF field using rest_prepare_{$post_type}
- filter custom post in rest api with custom function
- API Rest Custom Post Type doesn’t return all data
- Custom REST endpoints for a custom post type with custom fields
- Dynamic Custom Fields
- Multiple Frontend Filters Using Advanced Custom Fields
- Extracting Address from Custom Post via Javascript for Google Maps API
- How to add/edit advanced custom fields on custom post type’s WordPress REST API?
- Combine multiple getEntityRecords calls
- Custom Post Type Slick Slider “$ is not a function”
- How to get all post of custom post type by rest api?
- Create custom post with meta field with AJAX and the WordPress REST API
- WordPress API for custom post types returns rest_no_route
- set_query_params using custom params defined in functions file?
- How to see posts in taxonomy endpoint
- WP API Response does not show my registered metadata
- REST filters only firing when I have a param set
- Custom REST endpoint not working to retrieve single posts (“rest_no_route”)
- Get data from PHP to JavaScript to set position of each post on front page
- How to add a filter to a custom post type to get adjacent custom posts via the REST API
- How to handle new post from API request?
- Why is wp api returning old acf values?
- wp-json API: not logged in when clicking link to the API from admin mode
- Custom Post Type API doesn’t show taxonomy or category array
- Loading multiple post content in FancyBox
- Weird issue where form field loses focus to previous form field even with JS disabled
- WordPress/Javascript form not working on custom post type single posts
- How to make an API call to a custom post type but filtering by meta value?
- Fetching custom post type without knowing post type (REST API)
- Create a Dropdown Selector and Redirect for a Custom Taxonomy in WordPress?
- WordPress REST API V2: “{CUSTOM_POST_TYPE} matches Term ID List and Term ID Taxonomy Query, but should match only one.”
- no_rest_route in Unit Testing for REST endpoint for CPT registered via show_in_rest
- How can I create new CustomPostType record using wp.api.collections?
- Custom endpoint filtering post by custom taxonomies
- How can I put content before my custom post type default pages?
- wp rest api orderby field in a custom table
- How To Read Read Custom Post Type Data in Headless CMS Mode
- WP_Query: how to search tags in addition to a custom post type?
- How can I sort the results of a REST API response by the title of a connected custom post type?
- How to filter a matched value with custom key using WP REST API?
- How to add field to custom post type endpoint
- Create API’s for custom-post types & custom queries using REST or Graphql
- Action on Custom Post publish
- Randomizing WordPress Custom Post Type Sorting Through Them Without Page Refresh
- How can I use javascript in specific posts without relying on a plugin?
- Get Custom Post types data from the API
- How to use posts as tabs in a custom page?
- How can I add a meta[] to my custom post type and search by term with the Rest API?
- Hide the update button from edit view in wordpress custom post type
- register_rest_field update_callback don’t work for $_FILES
- WordPress custom post type post item data – show/fetch only on click with Javascript dynamically?
- dynamic vue widget inside custom post
- Issue with CPT posts within WP REST API showing as []
- Saving custom post types post_meta over REST-API fails
- WP REST API Custom endpoint don’t work in my plugin
- filter rest api post by a acf filed
- How to properly set a value to meta fields of a custom post type in WP-API/node-wpapi REST API?
- Redirect sub-page URLs to parent without changing URL
- How to get $post object available inside functions.php to localize script?
- Loops running into each other
- How to dynamically register custom post type
- Store custom post type with JSON content
- querying to custom field over ACF REST API
- Create settings page to enable or disable CPT
- Get all posts of any post type in a category from REST API
- Make term slugs of custom taxonomy available in WP REST API for custom post type?
- Custom post type REST api 404: Updating failed. No route was found matching the URL and request method
- upload image with rest API to the media library
- Can’t expose custom field to REST API
- Passing total post count to javascript