bbabics
Forum Replies Created
Viewing 1 replies (of 1 total)
-
Forum: Plugins
In reply to: [WordPress REST API (Version 2)] Get posts after a specific dateThis is exactly what I’m looking to do using
Version 2.0-beta15with a custom post type that inherits from theWP_REST_Posts_Controller, but sorts based on an acf field. Unfortunately this isn’t working for me. 🙁I’m hitting the following endpoint:
/wp-json/wp/v2/almanac_entry?per_page=3&filter[orderby]=acf_almanac_date&after=2016-12-23T00:00:00&filter[date_query[column]]=acf_almanac_dateand it’s returning three results (should be two) where two are after the date listed, and the third is before the date listed.
Here’s how I’m registering my actions:
add_action( 'init', 'register_custom_post_types', 25 ); function register_custom_post_types() { global $wp_post_types; $post_type_name = 'almanac_entry'; if( isset( $wp_post_types[ $post_type_name ] ) ) { $wp_post_types[$post_type_name]->show_in_rest = true; $wp_post_types[$post_type_name]->rest_base = $post_type_name; $wp_post_types[$post_type_name]->rest_controller_class = 'WP_REST_Posts_Controller'; } } add_action( 'rest_api_init', 'wp_rest_add_custom_fields' ); function wp_rest_add_custom_fields() { register_rest_field('almanac_entry', 'acf_almanac_date', array ( 'get_callback' => function($object, $field_name, $request) { return get_post_meta( $object[ 'id' ], 'almanac_date', true ); }, 'update_callback' => null, 'schema' => null, )); }I’m new to doing WP dev, so I may have done this wrong. I’m wondering if maybe it’s due to the priority not being set in
add_action?Any help is much appreciated.
- This reply was modified 9 years, 6 months ago by bbabics. Reason: trying to figure out how to format code in my post
Viewing 1 replies (of 1 total)