Support » Plugin: Custom Post Type UI » WP REST API v2 Ignores Filtering by CPTUI-Defined Taxonomy on Custom Post Type

  • Resolved marklavin

    (@marklavin)


    Hello,

    I’m working on exposing endpoints on a client’s site so that a mobile-app developer can pull their data.

    I’ve defined a custom post type, “Session,” (post-type slug: session, API base slug: sessions), and that renders just fine when I call it from .../wp-json/wp/v2/sessions.

    I’ve also defined a custom hierarchical taxonomy “Associated Event” (taxonomy slug: associated_event, API base slug: associated_event). I’ve assigned individual sessions
    the parent term aferm-summit-2017 and the child terms day-1-2017-summit and day-2-2017-summit as appropriate.

    However when I call the content from .../wp-json/wp/v2/sessions?filter[associated_event]=day-1-2017-summit or day-2-2017-summit, all sessions get returned.

    Here are all the relevant settings for the Associated Event taxonomy:

    Public: True
    Hierarchical: True
    Show UI: True
    Query Var: True
    Custom Query Var String: associated_event
    Rewrite: True
    Custom Rewrite Slug: associated_event
    Rewrite With Front: True
    Rewrite Hierarchical: False
    Show in REST API: True
    REST API base slug: associated_event

    Any help in figuring out how to get the route/endpoint to work would be great.

    Thanks!

Viewing 8 replies - 1 through 8 (of 8 total)
  • Plugin Author Michael Beckwith

    (@tw2113)

    The BenchPresser

    Hey @marklavin,

    To be honest, I’m not sure how to best help you. My hands-on experience with the WP REST API is admittedly extremely limited.

    That said, I have tried tinkering a bit, and recreated some of the parts provided above. I am assuming that day-1-2017-summit is a term you’ve used in the “associated_event” taxonomy.

    On the flip side, the only things CPTUI technically does with regards to the WP REST API is pass in the user-provided values into register_post_type() and register_taxonomy(). So I’m hesitant to call it a bug with our plugin specifically. However, if it comes to it, I’m willing to be wrong. My question with regards to that is if it works as expected with a similar setup when registering the post type yourself manually via say functions.php instead of our plugin. If it indeed does work with that version, then I’d be more than curious to see the differences and where we’re not matching like needed.

    Plugin Author Michael Beckwith

    (@tw2113)

    The BenchPresser

    Any chances with this one? @marklavin

    I am trying to do the exact same thing and cannot figure out how to do it. Any help would be greatly appreciated!

    Plugin Author Michael Beckwith

    (@tw2113)

    The BenchPresser

    @taylortay619

    I never really heard back from Mark above, so I really don’t have any new answers regarding this. That said, I’m mostly deferring an answer here to the last paragraph I put a couple months back.

    Hello!

    I have same problem like the author.

    Any updates? Did you managed to filter CPT UI based on Taxonomy/Category?

    Thanks!

    unction cptui_register_my_cpts() {

    /**
    * Post Type: Recipes.
    */

    $labels = array(
    “name” => __( “Recipes”, “” ),
    “singular_name” => __( “Recipe”, “” ),
    );

    $args = array(
    “label” => __( “Recipes”, “” ),
    “labels” => $labels,
    “description” => “”,
    “public” => true,
    “publicly_queryable” => true,
    “show_ui” => true,
    “show_in_rest” => true,
    “rest_base” => “”,
    “has_archive” => false,
    “show_in_menu” => true,
    “exclude_from_search” => false,
    “capability_type” => “post”,
    “map_meta_cap” => true,
    “hierarchical” => false,
    “rewrite” => array( “slug” => “cpt_recipes”, “with_front” => false ),
    “query_var” => true,
    “menu_position” => 11,
    “menu_icon” => “/favicons/favicon-16×16.png”,
    “supports” => array( “title”, “thumbnail”, “comments”, “author” ),
    “taxonomies” => array( “cptax_recipes_types” ),
    );

    register_post_type( “cpt_recipes”, $args );
    }

    add_action( ‘init’, ‘cptui_register_my_cpts’ );

    Plugin Author Michael Beckwith

    (@tw2113)

    The BenchPresser

    I have nothing new to report here, beyond what I put in my first reply above. @galatanuadrian27 have you tried my questions/suggestions in that reply?

    I solved by using this plugin: https://github.com/WP-API/rest-filter

    Works perfectly!

    Plugin Author Michael Beckwith

    (@tw2113)

    The BenchPresser

    Interesting, but I recognize the author and he’s trustworthy too.

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘WP REST API v2 Ignores Filtering by CPTUI-Defined Taxonomy on Custom Post Type’ is closed to new replies.