Add post meta fields, when creating a post using WordPress’ REST API

In the documentation for /posts for WordPress REST API it states that I can add a meta-field. But it doesn’t say which format that should be in.

I can find other guides showing how it should be if using Postman:

data = {   "title": "test",   "content": "testingfrompython",   "status": "draft",   "author": 1,   "meta": {     "location": "NYC",     "date": "never",     "event_url": "http: //google.com"   },   "featured_media": 1221 } 

But how should it be setup, if I’m call the endpoint using PHP and cURL?


This here works for just creating a post:

$  data = [   'title'   => 'Test post',   'status'  => 'draft',    'content' => 'Some content', ]; $  data_string = json_encode( $  data );  $  endpoint = 'https://example.org/wp-json/wp/v2/posts'; $  protocol = "POST";  $  headers = [   'Content-Type: application/json',   'Content-Length: ' . strlen($  data_string)   'Authorization: Basic ' . base64_encode( 'MYUSERSEMAIL:APPLICATIONPASSWORD' ) ];  $  ch = custom_setup_curl_function( $  endpoint, $  protocol, $  data_string, $  headers ); $  result = json_decode( curl_exec($  ch) ); 

I’ve tried all kind of things:

Attempt1

$  data = [   'title'   => 'Test post',   'status'  => 'draft',    'content' => 'Some content',   'meta' => [     'my_custom_field' => 'Testing 1234'   ] ]; 

Attempt2

$  data = [   'title'   => 'Test post',   'status'  => 'draft',    'content' => 'Some content',   'meta' => [     [       'key' => 'my_custom_field',        'value' => 'Testing 1234'      ]   ] ]; 

… And I could keep going. Every time it simply creates a post, but doesn’t add any of the meta-data to my created custom fields.

I don’t get why this is not stated in the documentation for the REST API.

Getting meta in editor plugin, and event triggering issue

I have a Custom Post Type defined with custom-fields support. I then registered a meta field.

The first issue is that select( 'core/editor' ).getEditedPostAttribute( 'meta' )._vaenc_actu_roles_scope_roles always returns undefined on first call (before being updated by dispatch( 'core/editor' ).editPost). Also, when I save the Custom post Type the value isn’t modified in the database.

The other issue is, when check any of the checkboxes, on first click, isChecked() is properly called, on next clicks it doesn’t happen, but updateMeta() is triggered. If I fold/unfold the control or uncheck a checkbox, all the checkboxes do get updated by calling isChecked():

animation example of second issue

Here is my code:

class Metaboxes extends Base {      /**      * Setup user.      */     public function setup() {         add_action('init', [$  this, 'init'] );     }      public function init () {         register_post_meta(             'vaenc_actu',             '_vaenc_actu_roles_scope_roles',             [                 'show_in_rest' => true,                 'single'       => true,                 'type'         => 'array',                 'default'       => [],                 'auth_callback' => function() {                     return current_user_can( 'edit_posts' );                 }             ]         );     } } 

My javascript is like so:

const {registerPlugin}                              = wp.plugins; const {PluginDocumentSettingPanel}                  = wp.editPost; const {PanelBody, CheckboxControl}                  = wp.components; const {useSelect, select, withSelect, withDispatch} = wp.data; const {Fragment, useState}                          = wp.element; const {__}                                          = wp.i18n; const {compose}                                     = wp.compose;  const RolesControl = ( {isChecked, updateMeta} ) => {     return (         <>             <Fragment intialOpen={true}>                 <CheckboxControl                     label={__( "PRI", "vae" )}                     checked={isChecked( 'vae-pri' )}                     onChange={( value ) => updateMeta( 'vae-pri', value )}                 />                 <CheckboxControl                     label={__( "PRC", "vae" )}                     checked={isChecked( 'vae-prc' )}                     onChange={( value ) => updateMeta( 'vae-prc', value )}                 />                 <CheckboxControl                     label={__( "Certificateurs", "vae" )}                     checked={isChecked( 'vae-certif' )}                     onChange={( value ) => updateMeta( 'vae-certif', value )}                 />             </Fragment>         </>     ) }  const RolesField = compose( [     withSelect( () => {         return {             actu_scope_meta: select( 'core/editor' ).getEditedPostAttribute( 'meta' )._vaenc_actu_roles_scope_roles,         };     } ),     withDispatch( ( dispatch ) => ({         isChecked ( prop ) {             let meta = select( 'core/editor' ).getEditedPostAttribute( 'meta' )._vaenc_actu_roles_scope_roles;             if ( meta ) {                 return meta.includes( prop );             }             return false         },         updateMeta ( prop, value ) {             let meta = select( 'core/editor' ).getEditedPostAttribute( 'meta' )._vaenc_actu_roles_scope_roles;             if ( !meta ) meta = []              if ( meta.includes( prop ) && !value ) {                 meta = meta.filter( arrayItem => arrayItem !== prop );             } else if ( !meta.includes( prop ) ) {                 meta.push( prop );             }              dispatch( 'core/editor' ).editPost( {meta: {_vaenc_actu_roles_scope_roles: meta}} );         },     }) ), ] )( RolesControl );  const Render = () => {     const postType = useSelect( select => select( 'core/editor' ).getCurrentPostType() );     if ( 'vaenc_actu' !== postType ) {         return null;     }      return (         <>             <PluginDocumentSettingPanel                 name="vae-role-scope-sidebar"                 title={__( 'Restrictions', 'vae' )}             >                 <RolesField/>             </PluginDocumentSettingPanel>         </>     ) }  registerPlugin( 'vae-role-scope-sidebar', {     render: Render } )  

Meta Scraper Add-on at scale ?

Hi have a problem with the Meta Scraper Add On. 
Imgur trying to scrape 1533 Keywords and I get only 500 results.

Afterwards I renewed the proxies, put delay on 30 seconds and switched connections to 1 and I get 900 results, but it doesn’t stop (start button greyed out), it simply does not go on.
Afterwards I checked the proxies and all of them passed both tests.
What am I doing wrong ?

Post pagination links ordered by meta value

Is there a way to order the nex-previous post links, or any other pagination function to get the links ordered by meta value, like I have done in the posts listing page shown below?

$  events = get_posts(array(     'posts_per_page' => -1,     'post_type' => 'post',     'meta_key'  => 'date_time',     'orderby'   => 'meta_value',     'order'     => 'ASC',     'suppress_filters' => false )); 

The main goal is tho have the next, – previous event buttons in chronological order in the single post page. (not the post date, but the event date that is stored in custom fields)

How to stop players from trying to gauge success of meta-ideas via meta questions?

I am running a campaign in The Dark Eye, the Year of the Griffon to be exact.

Due to having quite an abundant downtime by having taken initiative quite early

the group had about 2 and a half months of downtime. That in itself is not a problem. Yet my group did spend the downtime in ways that start to make me think carefully: The siege-engineer did recruit all the carpenters and masons to fix up the walls

while the Maga did start to research a variant of Greek fire. That luckily took her most of the time… But exactly there lies the problem:

My players are all students, some of them with at least a good degree of chemistry and physics knowledge (including the Maga, who has 2 semesters of chemistry behind her). As a result, they tend to come up with ideas that make incredible sense in themselves… but the rules for TDE explicitly state that some stuff is simply not possible. For the most part, they did swallow that gunpowder simply can’t be made due to “it’s just like that” and that the recipe for fireworks is not only highly complex but also so arcane, that nobody knows it.

YET this makes them try to figure out how to use the little Greek fire they managed to produce up to now (4 flasks) much more efficiently – as in getting more area of effect. While they did not yet test it, they had ideas like

  • How about training a dog to carry a jar of greek fire into the orc camp and then shoot the jar from the walls with a flaming arrow?

On ideas like this I did say up to now “I did look into that topic in the books and I will have to make a ruling as there are no rules written yet. I have a vague idea how to rule on it, but would you mind stopping to speak in hypotheticals and bring this up in character through action or prompting that in an officer’s meeting?” Pretty much I try to go by In Character Action = In Character Consequences and Not Said = Not Done.

The idea to weaponize the results of a failure on the alchemy I could squat luckily: “You don’t exactly know how you made it create the poison gas it made… you could try to recreate the experiment though. Do you want that?”

Up to now, the only three things they did act on based on sentences like those was to build up some siege engines for defense (a trebuchet, 2 catapults, repairing one ballista), re-inventing greek fire (which did blow up the Maga twice already for it is so dangerous to work with as established in the rules) and digging ramparts1 around the city wall (ongoing, they are about 2/3rds done) and will be finished by the end of the months.


How can I discourage the players from directly adapting ideas from modern warfare methods (like gas, using chemical waste (dioxin) or trained dogs with bombs) and instead staying in the established canon, that puts greek fire at the pinnacle of chemical warfare and lobbing corpses as the pinnacle of biological warfare?


1 – Yes, they made Ramparts, not moats.

My question is being marked as spam and I’m blocked on Meta

Today, I tried to post a question on Information Security Stack Exchange, and the question was apparently marked as "spam" (the error message was this looks like spam). The content of the question can be found here: VeraCrypt Paste. I’m thinking it might have been because of the URIs, but I tried to remove them all and it continued to mark the question as spam.

I then went to Infosec Meta Exchange, to try to see if I could get some help, but I’m blocked there. Like, weirdly blocked. All requests I make to the Security Meta domain while logged give me an empty page and a 500 status code. It works fine if I logout. I truly don’t know that to do.

I’m 100% aware this post doesn’t belong here, but I’m apparently out of options – don’t know what else I can do – the help page doesn’t say anything about that -, so please don’t downvote this right away. I’m obviously ok with this question being deleted, I just need some help now.

Add post meta data date to event

I created a post metabox that uses the datepicker to pick a date value. I got as far as adding the metabox and getting the datepicker to work but other than that im struggling to get the data saved to the post. This is my code in my functions.php:

//Add date picker css function admin_styles() {     if ( 'events' === get_current_screen()->id ) {         wp_enqueue_style( 'jquery-ui-smoothness', // wrapped for brevity             '//code.jquery.com/ui/1.12.1/themes/smoothness/jquery-ui.css', [], null );     } } add_action('admin_print_styles', 'admin_styles'); //Activate function function admin_scripts() {     if ( 'events' === get_current_screen()->id ) {         wp_enqueue_script( 'admin', get_template_directory_uri() .'/js/admin.js', [ 'jquery-ui-datepicker' ] );     } } add_action( 'admin_enqueue_scripts', 'admin_scripts' );  //Add date meta-boxes  function post_date_field($  post) {    echo '<input type="text" id="jquery-datepicker" name="entry_post_date" value="' . get_post_meta( $  post->ID, 'entry_post_date', true ) . '">'; } function post_date_meta_box() {   add_meta_box('entry_post_date', 'Date', 'post_date_field', 'events', 'side', 'high'); } add_action('add_meta_boxes', 'post_date_meta_box');  //Save Data function save_date_meta_box($  post_id){     global $  post;     if( $  post->post_type == "events"){         if (isset($  _POST)){             update_post_meta( $  post_id, 'entry_post_date', strip_tags( $  _POST['entry_post_date'] ) );         }     } } 

After publishing or updating the post I dont think the date value is saved