admin管理员组文章数量:1430551
I'm trying to create a field or a select box in a WordPress custom block where the user can select a page and store it's ID or URL like the default internal linking field works.
The only difference will be that I need only that field, without the text to hyperlink.
My temporary solution I came up with it's creating an array of posts from the wp api like this
var posts = [];
$.getJSON('/wp-json/wp/v2/pages?per_page=100', function(data) {
$.each(data, function(index, elem) {
posts.push({
label: data[index]['title']['rendered'],
value: data[index]['id']
})
})
});
and then creating a select box with all the pages
el(SelectControl, {
className: 'page-selector',
label: 'Link',
value: linkURL1,
options: posts,
onChange: function(label) {
props.setAttributes({
linkURL1: label
})
},
})
Which works great, but having about 80 pages it's hard to find what I want. It looks like this:
What i'm trying now it's to replace the select box with a default wordpress internal link selector like in the first image.
Is that part of Gutenberg?
I'm trying to create a field or a select box in a WordPress custom block where the user can select a page and store it's ID or URL like the default internal linking field works.
The only difference will be that I need only that field, without the text to hyperlink.
My temporary solution I came up with it's creating an array of posts from the wp api like this
var posts = [];
$.getJSON('/wp-json/wp/v2/pages?per_page=100', function(data) {
$.each(data, function(index, elem) {
posts.push({
label: data[index]['title']['rendered'],
value: data[index]['id']
})
})
});
and then creating a select box with all the pages
el(SelectControl, {
className: 'page-selector',
label: 'Link',
value: linkURL1,
options: posts,
onChange: function(label) {
props.setAttributes({
linkURL1: label
})
},
})
Which works great, but having about 80 pages it's hard to find what I want. It looks like this:
What i'm trying now it's to replace the select box with a default wordpress internal link selector like in the first image.
Is that part of Gutenberg?
Share Improve this question asked May 2, 2019 at 21:33 Razvan CuceuRazvan Cuceu 2482 silver badges14 bronze badges1 Answer
Reset to default 2I found a solution and thought to post it here as others might need it
el(URLInput, {
className: props.className,
value: attributes.linkURL,
placeholder: i18n.__('Set the specific url'),
onChange: function( url ) {
props.setAttributes({ linkURL: url });
}
})
Does exactly what I need.
本文标签: apiGutenberg internal page link search box
版权声明:本文标题:api - Gutenberg internal page link search box 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745530269a2662026.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论