Get post id in a function when edit/add a post

Your function get_postid() does not return anything. It should return the id: function get_postid() { global $post; return $post->ID; } If you are going to use the $post_id I guess your first if statement is wrong, because the $post_id should be evaluated to true not false. So it should be like this: if ( $post_id … Read more

404 on paginated blog pages

I managed to work around this issue. I recently updated my site to WordPress 5.7 and was getting 404 Errors on every page except the home page. After a lot of debugging I found out that wp-includes/class-wp.php was setting the is_404 variable because of a missing comment <!–nextpage–> in the $post->post_content. (Line 694) I tried … Read more

How to create a post using REST API with sending data as a JSON body?

That’s strange, but nonetheless, you should know that whether you use cURL, PHP, JS, etc., if you’re sending a JSON data, then you should set the Content-Type header to application/json. And via the cURL command line, you can use the -H option: curl –user “username:password” -X POST \ -H “Content-Type: application/json” \ -i https://example.com/wp-json/wp/v2/posts \ … Read more