Forum Replies Created

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter Martin Greenwood

    (@pixelpudu)

    The server logs were empty, bar a few notices about undefined Vars…

    Weirdly, started working again fine this morning!

    Thread Starter Martin Greenwood

    (@pixelpudu)

    Turns out i had to add this to the functions.php file.

    // MAKE API FILTERABLE
    add_action( 'rest_api_init', 'post_meta_register' );
    function post_meta_register() {
        register_api_field( 'post',
            'testing',
            array(
                'get_callback'    => 'get_post_meta',
                'update_callback' => null,
                'schema'          => null,
            )
        );
    }
    
    function get_post_meta( $object, $field_name, $request ) {
        return get_post_meta( $object[ 'id' ], $field_name, true );
    }
    
    add_filter( 'rest_query_vars', 'allow_meta' );
    function allow_meta( $valid_vars ) {
    
            $valid_vars = array_merge( $valid_vars, array( 'meta_key', 'meta_value' ) );
            return $valid_vars;
    }
Viewing 2 replies - 1 through 2 (of 2 total)