LoginSignup
1
0

More than 1 year has passed since last update.

Wordpress Gutenberg 色々データ取得・変換

Last updated at Posted at 2020-06-12

この記事は?

Wordpressの新エディタGutenberのブロック開発で使った・使いそうな
データ取得・変換のメソッドとか関数とかをメモしていきます

WP AjaxのURLを取得する

wp.ajax.settings.url;

投稿IDを取得する

wp.data.select('core/editor').getCurrentPostId();

getCurrentPostId

投稿タイプを取得する

wp.data.select('core/editor').getCurrentPostType();

getCurrentPostType

投稿オブジェクトを取得する

wp.data.select('core/editor').getCurrentPost();

getCurrentPost

登録されているBlockTypeを取得する

wp.data.select('core/blocks').getBlockTypes();

getblocktypes

指定のBlockTypeを取得する

wp.data.select('core/blocks').getBlockType('my/block_type');

getblocktype

選択中のBlockのAttributesを取得する

wp.data.select('core/block-editor').getSelectedBlock().attributes;

getSelectedBlock

clientIdからBlockの情報を取得する

wp.data.select('core/block-editor').getBlock(clientId);

getBlock

指定のタイプの親ブロックのclientIdを取得する

wp.data.select('core/block-editor').getBlockParentsByBlockName(clientId,'my/block_type')[0];

getBlockParentsByBlockName

HTML文字列をsource:"children"のAttributesの値に変換する

wp.blocks.parseWithAttributeSchema('<p>some HTML string</p>',{source:'children'});
1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0