Load the elements into a constant using a function like this:
const postSelections = [];
const allPosts = wp.apiFetch({path: "/wp/v2/posts"}).then(posts => {
postSelections.push({label: "Select a Post", value: 0});
$.each( posts, function( key, val ) {
postSelections.push({label: val.title.rendered, value: val.id});
});
return postSelections;
});
Then use postSelections as your element “options”.
el(
wp.components.SelectControl,
{
label: __('Select a Post'),
help: 'Select a post to display as a banner.',
options: postSelections,
value: selectedPost,
onChange: onChangePost
}
),
Related Posts:
- Gutenberg editor add a custom category as wrapper for custom blocks
- Activate Gutenberg in category-descriptions
- Change Gutenberg category checkboxes to radios
- Load categories with ajax
- Get term by slug in Gutenberg
- New Categories Not Shown In the Post Edit Page
- How to display post categories within the Latest Posts block?
- Populate dropdown based on selection of parent category
- Select posts by name and category per REST API
- Pagination for ajax category filter
- ajax for filtering posts by category in wordpress loops
- Filter posts by categories ajax is showing nothing
- How can I use AJAX with check-box categories?
- Intermittent Gutenberg 504 Gateway Timeout when calling REST route to retrieve categories
- How to exclude certain categories showing in Gutenberg?
- Problem with pagination block in Gutenberg
- Hide Some Categories in Post Editor
- Exclude a category from block editor’s category widget
- Only 10 of 233 categories selectable when adding a new post
- Ajax load more not working with multipler categories
- Ajax Category add doesn’t update the list table custom column
- Filter custom taxonomy posts via AJAX
- Ajax Response Error
- Ajax call activate after submit in edit-tags.php page
- Bringing Ajax Loading Feature on Category Pages
- Display post content from category name using ajax
- How to link ACF relationship field to the new Query block in Full Site Editing
- Remove “?category=” in the URL wordpress ajax filter work for category
- How can I filter Query Loop to show only posts in current category?
- Is there a standard “Archive” block that shows ALL posts from a specified category?
- WP_Query with multiple categories unexpected behavior
- Does the ‘cat’ argument in query_posts fetch posts from subcategories as well as the given ID?
- Are Categories, Tags and Custom Taxonomies any different in regards to SEO?
- Display list of Sub-Categories and the posts they contain, within one main Category
- Create subdomains for tags and categories
- How to get this only in small letters (lowercase)? [closed]
- How to totally get rid of Category in my blog?
- Is there a function to cause empty categories not to show in menus?
- Category Specific Archive
- How to get the number of child categories a specific parent category has?
- Removing category base form links messes up the parent-child behavior
- display most popular tags of category?
- Exclude category from loop not working
- How to list only child categories?
- Cannot add / edit categories to a post anymore
- List archived posts by subcategory
- What’s the Simplest Way to Override/Rewrite the %category% Permalink Structure Tag?
- Set a them for all subset of category
- How to query post like normal search would do. within search.php page
- How to get the id from the custom category?
- Unwanted Duplicate Product Categories in WooCommerce
- WP didn’t redirect to canonical category URL
- Using ajax on editing a category edit page?
- Get category URL knowing it’s id
- How could I know all the categories from post?
- How to make subcategory for custom post and and display?
- Create menu locations for each category in wordpress
- Get category’s parent category while using get_the_category_list
- How to make the ‘delete’ button inactive on some categories?
- Array: What is this value based on?
- How to show the category of custom taxonomy
- Show testimonials based on post category matching product name
- WordPress list categories dropdown with parent-child relation and child under it’s parent
- How to Link to Most Recent Custom Post of Same Term
- WP REST API not retrieving all categories
- Remove parent category from child/sub-category page URL in WordPress
- Category page not showing
- Add code to header based on category for specific posts?
- How to only show parent categories in sidebar
- Change RSS format for specific categories
- Displaying a custom field in Category Archives
- List post only under the category, exclude child category content
- Custom Portfolio Page
- Custom Fields Value As Taxonomy
- Detect category choice for posts with multiple categories
- Redirect Problems with Archive Page and GET variables
- Different size video display for category page (smaller) & detail page (larger)
- Adding tinymce to Custom Field boxes on Category edit page
- How do you get sticky posts to work with categories?
- Display the articles of a category by role
- Remove “Category:” from Post meta
- How to “remove” WordPress categories UL and make the list loop in a horizontal line?
- restrict category to only logged in User
- Default category isn’t saved in database
- Dynamically creating content on custom URL without getting 404
- Category foreach Paging
- Help with Wp + Mixitup code
- One category not displaying template updates
- How to display only category of blog without custom code?
- Matching usermeta at registration to categories of content
- How do I hide posts in a category from all listings but still allow the posts to be viewed?
- Form Value of drop down category + Translation of ‘show option none’
- How to show monthly archive posts?
- How to display posts by author in a separate page, other than author.php?
- One color to category link depending on category ID
- Show subcategories and hide posts or show posts if not exists subcategories
- Fetch Post Category
- Exclude category when displaying all categories assigned to a post
- Using same term for slug and category
- How do we ReWrite HTACCESS to point a cat/subcat Product URL, to Cat/ only?