How to pass a file to an API call through WordPress
How to pass a file to an API call through WordPress
How to pass a file to an API call through WordPress
Make sure you’re reaching the correct endpoint by using rest_url(). When using the REST API and nonces, make sure that the nonce action is set to ‘wp_rest’. add_action(‘enqueue_block_editor_assets’, function () { $data = wp_json_encode(array( ‘restUrl’ => esc_js(rest_url(‘guide-posts/v1’)), ‘nonce’ => esc_js(wp_create_nonce(‘wp_rest’)) )); wp_add_inline_script(‘guide-posts’, “var guidePostsAjax = $data”); }); The permission_callback property is mandatory when registering a … Read more
Perhaps I encountered a bug or my configuration is faulty. I cannot change the permalinks structure in the default Settings > Permalinks views without introducing the /index.php/-part. This behavior does not change, whether the user is a Super-Admin or a regular Site-Admin. However, as a Super-Admin, you can overwrite the permalink structure in the network … Read more
One of two things is happening here: Invalid JSON If the value of $extra isn’t a properly-constructed JSON string, then json_decode( $extra ) is returning null. echo null; won’t print anything to the screen. Valid JSON If $extra is a valid JSON string, When you json_decode() it, you’ll get an object (specifically, a stdClass object). … Read more
You need to add the post via function call wp_insert_post. where you need to pass the parameter of post type as name of your custom post type. $wordpress_post = array( ‘post_title’ => ‘Post title’, ‘post_content’ => ‘Post Content’, ‘post_status’ => ‘publish’, ‘post_author’ => 1, ‘post_type’ => ‘custom_post_type’ ); wp_insert_post( $wordpress_post ); Hope this helps
If I understand correctly, you are wanting to prevent duplicate IDs in the meta data: use the get_user_meta() function to retrieve the meta value and check it for the ID (untested): $meta = get_user_meta( $user_id, ‘saved_session’ ); if ( ! in_array( $post_id, $meta ) ) { add_user_meta( $user_id, ‘saved_session’, $post_id ); } For others that … Read more
Have a look here: How to add/edit advanced custom fields on custom post type’s WordPress REST API? You need a little bit of extra code to hook up the WordPress REST API to the ACF functions to get and write ACF fields. Then with that, you can access the fields directly like other ‘regular’ post … Read more
You’ll want to prevent SEO plugins from adding a canonical meta tag, and then add your own canonical meta tag using wp_head filter (untested): add_action( ‘wp_head’, static function () { $url = trailingslashit( get_site_url() ); $url .= ltrim( $_SERVER[‘REQUEST_URI’], “https://wordpress.stackexchange.com/” ); printf( ‘<link ref=”canonical” href=”%s” />’, esc_attr( $url ) ); } );
How to do SEO friendly filters urls?
Disable RSS /feed/ endpoints on posts without disabling RSS overall