Forum Replies Created

Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter shannonrl

    (@shannonrl)

    OK… I finally got it working by doing the following:
    1. Install and activate plugin: WP-API/rest-filter
    2. Change function name on line 42 (in this plugin) from query_vars to rest_query_vars, per this comment
    3. Add following snippet to your code somewhere:

        /**
        * Allow query endpoint by meta-keys
        */
    
        add_filter( 'rest_query_vars', 'my_allow_meta_query' );
        function my_allow_meta_query( $valid_vars ) {
            $valid_vars = array_merge( $valid_vars, array( 'meta_key', 'meta_value' ) );
            return $valid_vars;
        }
    Thread Starter shannonrl

    (@shannonrl)

    Hi Kevin!

    Thanks for your response on this issue. I thought I was going crazy. lol

    Upon examining the available arguments on the {base-url}/wp-json/{CPT} for the GET Method, I discovered that the filter argument was MISSING!

    Come to find out, the filter argument was removed just prior to WP 4.7 release because it did not line up with the existing endpoint structure. However, later, it was realized just how important the filter argument was to many people, so they provided a plugin to add it back. Since then, they must have changed the query_vars function name to rest_query_vars upstream, but never changed it on the plugin. So, according to this comment, you would need manually update a line to get this plugin to work.

    I will be trying this soon and get back to you on my results.

    Thread Starter shannonrl

    (@shannonrl)

    Thank you! The updated version works perfectly!

Viewing 3 replies - 1 through 3 (of 3 total)