Query WP REST API v2 by multiple meta keys

Adding a custom endpoint is pretty straightforward. I also modified the url to look more like http://example.com/wp-json/namespace/v2/posts?filter[meta_value][month]=12&filter[meta_value][year]=2015 function wp_json_namespace_v2__init() { // create json-api endpoint add_action(‘rest_api_init’, function () { // http://example.com/wp-json/namespace/v2/posts?filter[meta_value][month]=12&filter[meta_value][year]=2015 register_rest_route(‘namespace/v2’, ‘/posts’, array ( ‘methods’ => ‘GET’, ‘callback’ => ‘wp_json_namespace_v2__posts’, ‘permission_callback’ => function (WP_REST_Request $request) { return true; } )); }); // handle the request … Read more

How can I load a page template from a plugin?

You can use the theme_page_templates filter to add templates to the dropdown list of page templates like this: function wpse255804_add_page_template ($templates) { $templates[‘my-custom-template.php’] = ‘My Template’; return $templates; } add_filter (‘theme_page_templates’, ‘wpse255804_add_page_template’); Now WP will be searching for my-custom-template.php in the theme directory, so you will have to redirect that to your plugin directory by … Read more

Not able to change wp_title using add_filter

wp_title filter is deprecated since WordPress 4.4 (see here). You can use document_title_parts instead function custom_title($title_parts) { $title_parts[‘title’] = “Page Title”; return $title_parts; } add_filter( ‘document_title_parts’, ‘custom_title’ ); In custom_title filter, $title_parts contains keys ‘title’, ‘page’ (the pagination, if any), ‘tagline’ (the slogan you specified, only on homepage) and ‘site’. Set “title” the way you … Read more

Is there any action filter/hook for validating a custom field before publishing the post?

At the beginning of wp_insert_post, the function that saves/updates a post, there is a filter called wp_insert_post_empty_content. By default this filter checks whether the title, editor, and excerpt fields are all empty, in which case the save process will be halted. However, since all the fields to be saved are passed to this filter, you … Read more