• Resolved jadeivee

    (@jadeivee)


    I currently have this a meta fields that are registered to the post, and another post type.

    I was able to register the metafields correctly and I am able to do a POST for me articles through REST API.

    What I am trying to figure out now is how can I add the meta key fields as search keys when I try to do a GET request through the rest API.

    I searched through google but I am getting outdated resources.

    I currently have this code:

    $this->post_types = array ( ‘post’, ‘events’ );

    foreach( $this->post_types as $field ) {

    add_filter(“rest_” . $field . “_query”, function ($args, $query) {

    $args[“meta_query”] = “event_id”;
    $args[“meta_query”] = “event_date”;

    return $args;

    }, 10, 2);
    }

    But when I try to search using: /wp-json/wp/v2/events?filter[meta_query][event_id]=15432 I am getting incorrect results.

    Is there something in my code that I missed? Thanks in advance for any help.

  • The topic ‘How to correctly add meta values as search keys using WordPress REST API?’ is closed to new replies.