Viewing 12 replies - 1 through 12 (of 12 total)
  • I’m having some trouble with this as well. I’ve seen several posts suggesting /wp-json/wp/v2/posts?type=post-type-slug, but that just returns the default post type for me.

    I’ve also read that in the previous version you may have to manually register an endpoint for custom post types. Is that still the case with v2?

    I can see all my registered post types at /wp-json/wp/v2/types but I’m not sure how to get at the posts themselves.

    Thread Starter sheriffderek

    (@sheriffderek)

    I’m losing it. Now I can’t even find the docs with /wp/v2

    I did however try some combos and ended up with this: (which seems very logical)

    /wp-json/posts/types/faq

    Which IS pulling up my custom post type ‘faq’ – and shows these links within

    self: "https://site.com/wp-json/posts/types/faq",
    collection: "https://site.com/wp-json/posts/types",
    https://wp-api.org/1.1/collections/taxonomy/: "https://site.com/wp-json/taxonomies?type=faq",
    archives: "https://site.com/wp-json/posts?type=faq"

    Which gets me this: /wp-json/posts?type=faq

    and is grabbing my data.

    I’m using v1.2.2 though — says its the most recent / so why don’t I need the /w2/ namespace?

    I think you are actually using v1, which would explain why you don’t need the v2 namespace. I actually dropped back down to v1 due to not being able to work with custom post types in v2.

    v2 is looking awesome, but it may need more time to cook and/or more documentation. It seems to be still in beta after all.

    As for v1, this is how you get custom post types according to my understanding /wp-json/posts?type=post-type-slug, so you are doing it correctly.

    If you add show_in_rest=true as one of your arguments that gets passed to register_post_type() you will be able to retrieve custom post type data.

    Example:

    add_action( 'init', 'create_post_type' );
    function create_post_type() {
    
        $labels = array(
            'name' => __( 'Data' ),
            'singular_name' => __( 'item' )
        );
        $args = array(
            'labels' => $labels,
            'public' => true,
    	'has_archive' => true,
            'show_in_rest' => true
        );
        register_post_type( 'data', $args );
    }

    Then you can use an endpoint like this: https://www.example.com/wp-json/wp/v2/data/

    Wow, thank you! I will definitely give this a shot!

    Does show_in_rest work for v1 or v2 or both?

    The documentation seems very immature at the moment. Most of the endpoints are not there. For example, I can’t click on: “list all posts”, “create a post”, “retrieve a post”, “update a post”, “delete a post”.

    Are these links unfinished or it’s like that?

    This article explains this better.
    https://scottbolinger.com/custom-post-types-wp-api-v2/

    Hi all,
    I working with membership2 plugin https://premium.wpmudev.org/project/membership/ and want to get whole data about members. This is the same custom post type, And I have tried to get with this url https://lc13754376.on-rev.com/restapi/wp-json/wp/v2/posts?type=membership2. Now get only empty array [] . But I need to get members list, or post there new members with api. Please can you help me with this.

    Is there anybody got the same problem?
    For example I have custom post type My Music and that is not empty. Here is my url that I trying to get data https://lc13754376.on-rev.com/restapi/wp-json/wp/v2/posts?type=music but that is empty array, please if somebody knows what should I do for getting data.

    A CPT would require you to use the name of the CPT in the URL.

    In your case it would be /wp-json/wp/v2/music.

    Although that doesn’t seem to work which is probably because you haven’t added the proper argument (like I showed above).

    Take a look and review it.

    *Note: If you are using a plugin to generate custom post types then I would reconsider using that plugin, and writing it on your own, or extending it in a way that won’t break the plugin.

    Thanks for help TBRudy3
    This is really help. Yes I know that I should register my custom post types. Here is another one that I generally working on.
    https://lc13754376.on-rev.com/restapi/wp-json/wp/v2/memberships . this returns empty array too. I need some advice for arguments.

Viewing 12 replies - 1 through 12 (of 12 total)
  • The topic ‘End point for custom post type in v2’ is closed to new replies.