Query the REST API for a Tag by slug

I was looking at this before… Here is what I found (about 7 months old from today 3/21/2018.) The “correct” way to do this with the REST API is to get the IDs of each of those tags, then make the request using the ?tags= parameter: assuming “clicks” has ID 1, and “passes” has ID … Read more

Request object for validate_callback

A quick search through the WP-API source revealed where validate_callback is being used: wp-api/lib/infrastructure/class-wp-rest-request.php $valid_check = call_user_func( $arg[‘validate_callback’], $param, $this, $key ); In this case, $this is an instance of WP_Rest_Request – so there’s one. Now, for sanitize_callback: $this->params[ $type ][ $key ] = call_user_func( $attributes[‘args’][ $key ][‘sanitize_callback’], $value, $this, $key ); Same file, there’s … Read more

How to create an endpoint without creating sub endpoints?

The rewrite rule added by: add_rewrite_endpoint( ‘my-endpoint’, EP_AUTHORS ); is author/([^/]+)/my-endpoint(/(.*))?/?$ => index.php?author_name=$matches[1]&my-endpoint=$matches[3] so it assumes anything after e.g. /author/henrywright/my-endpoint/…. You can try instead to replace it with add_rewrite_rule() e.g. add_rewrite_rule( ‘^author/([^/]+)/my-endpoint/?$’, ‘index.php?author_name=$matches[1]&my-endpoint=1’, ‘top’ );

Can I define multiple callback methods depending on the call method?

Check if your code looks like this because in the question you pass each method as separate function arguments (I have overlooked it earlier) add_action( ‘rest_api_init’, function () { register_rest_route(‘my-project/v1/’, ‘/form’, array( array(‘methods’ => ‘GET’, ‘callback’ => ‘GET_form’, ), array(‘methods’ => ‘POST’, ‘callback’ => ‘post_form’ ) ) ); }); As you can read in documentation: … Read more

How to have multiple rewrite endpoints in the same URL?

I also need this to work: example.com/nice-page/my-gallery/animals/cats/my-lightbox/1234 Where I’d like to register my-lightbox as an additional endpoint or query_var, because it could be used independently from without my-gallery, such as: example.com/another-page/my-lightbox/2345 Here’s an example of doing it using add_rewrite_rule(): add_action( ‘init’, function() { // This will let you use get_query_var( ‘my-gallery’ ). add_rewrite_endpoint( ‘my-gallery’, EP_PAGES … Read more

rewrite endpoint not working on home page

You’ll need to use a combination of add_rewrite_tag and add_rewrite_rule function setup_seo_endpoint() { // Ensures the $query_vars[‘item’] is available add_rewrite_tag( ‘%item%’, ‘([^&]+)’ ); // Requires flushing endpoints whenever the // front page is switched to a different page $page_on_front = get_option( ‘page_on_front’ ); // Match the front page and pass item value as a query … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)