How to get dynamically custom post type that are under a certain category

I think you may accomplish this by using the following WP builtin features. $wp_taxonomies – global object, it stores all registered taxonomies including default and custom get_post_types() – get all registered post types including default and custom To be simple, the examples for their usage are separated below. You may then combine them to create … Read more

Reduce nonce lifespan

Yes, using that filter will affect the lifespan of all nonces created after this filter is added, and while it remains in-place. So your best bet is to add it, create the nonce, remove it: function my_nonce_lifetime() { return 600; // 10 minutes } add_filter( ‘nonce_life’, ‘my_nonce_lifetime’ ); $nonce = wp_create_nonce(‘wp_rest’); remove_filter( ‘nonce_life’, ‘my_nonce_lifetime’ );

WordPress V2 REST-API: Endpoints 404?

Try changing your permalinks structure. Within the dashboard go to Settings > Permalinks and select the Post Name structure. When this is done click Save Changes. If Post Name is already selected, it might be worth clicking save changes again to reset the permalinks. Update: Per the comments below, WordPress does not, out of the … Read more

Match REST API post output from custom endpoint

The prepare_item_for_response method of the WP_REST_Posts_Controller class “Prepares a single post output for response” by translating every property of the post object for output from the REST API. The method doesn’t run statically, so we need to instantiate a controller in our endpoint. Here’s a simple example endpoint: function endpoint( $request ) { $p = … Read more

Serialized settings in rest api

JSON Schema It’s supported if you explicitly register the object JSON schema as: $args = array( ‘show_in_rest’ => array( ‘schema’ => array( ‘type’ => ‘object’, ‘properties’ => array( ‘post’ => array( ‘type’ => ‘string’, ), ‘blog’ => array( ‘type’ => ‘string’, ), ) ), ), ); register_setting( ‘default_sidebars’, ‘default_sidebars’, $args ); Resulting in the following … Read more

How to force Authentication on REST API for Password protected page using custom table and fetch() without Plugin

After studying carefully 🤓 the WordPress REST API Handbook concerning Home / REST API Handbook / Extending the REST API / Routes and Endpoints Home / REST API Handbook / Extending the REST API / Adding Custom Endpoints I realized I made a couple of mistakes. Therefore, I wanted to share with you my findings. … Read more

WP REST API, query total posts in a category

To just know the number of posts in a category, its endpoint returns that number straightforward, in example: curl http://wired.com/wp-json/wp/v2/categories/24 In the resource returned, the count field says: 486 Which is the same number the metadata says about the total number of posts, if you request the posts in that category, rather than the category … Read more