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
- How to enqueue scripts on custom post add/edit pages?
- Custom post types filtered by taxonomy using REST API v2
- Fetch All Posts (Including Those Using a Custom Post Type) With WordPress API
- Update CPT meta data using REST API
- How do I Filter Custom Post Type by Custom Taxonomy in the newest WordPress RESTful API?
- WordPress REST Create Post of Custom Type
- REST API: How can I restrict a custom post type to only be accessible by authenticated users?
- Show custom post type endpoint in REST API just if user has capability
- How to force Authentication on REST API for Password protected page using custom table and fetch() without Plugin
- Rest Api v2 orderby meta_key in custom post type
- Calculate Repeater Meta Box Input Field Values and Display Total
- How to create a repeatable / reusable divs in the metabox?
- wp is not defined error using wp.media to create a custom image uploader
- How to add custom fields to admin UI and REST API response?
- Wp Rest API request posts from a custom taxonomy
- Recommended way to remove WP REST API returned data for custom post
- Add custom post type to Backbone collections
- React post to WordPress custom post type
- Custom Post type with ACF in REST API, how do I get those values?
- is_main_query() not working for WP REST API
- Open div inside a custom post-type with Fancybox
- 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?
- Push metadata in array
- 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
- 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
- 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
- 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
- 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
- Custom Post Type API doesn’t show taxonomy or category array
- Loading multiple post content in FancyBox
- 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
- 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?
- Create API’s for custom-post types & custom queries using REST or Graphql
- Action on Custom Post publish
- 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
- dynamic vue widget inside custom post
- 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
- 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
- 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
- get total post in category via ajx
- rest_api_init is not getting invoked inside a Class
- Default post showing more than intended
- REST API callback function is not called
- Can’t retrieve custom post type taxonomy term to custom post type editor