• rjvansant

    (@rjvansant)


    hello,
    i was looking for guidance to utilizing the json-rest-api to output post output in the same format that exists now for posts.

    just to give some context to what i am trying to do, i have a custom post type that stores related posts by title/post_id, so when i call the json rest api by ?type=MY_CUSTOM_POST_TYPE, i get the json output and i created a function/method call to get the related posts by id, much like the class-wp-json-posts does, but when i attached it to the filter for additional json output, the data comes out flat and not in the same format that i get for a single post in the api. could you point me into the direction where i can get the same representation of the data with my method. i’ve tried utilizing the WP_JSON_Posts::get_post() method, but the data isn’t embedding in the node that i defined.

    thanks in advance,
    ~rob

    https://www.ads-software.com/plugins/json-rest-api/

Viewing 2 replies - 1 through 2 (of 2 total)
  • Kingdom Creation

    (@kingdomcreation)

    I just posted a support request that seems similar, perhaps we are trying to achieve the same thing.

    https://www.ads-software.com/support/topic/need-to-prepare_post-data

    Thread Starter rjvansant

    (@rjvansant)

    @kingdom creation, sorry i meant to post an update, but i got caught up in meeting a deadline. some of this was due to me still learning the WordPress Way, where i came from a MVC Framework background, but basically you can refer to the global in your function like so:

    global $wp_json_posts;

    and utilize the get_post() method, passing in post_id, and ‘child’ to indicate recursive lookups or embedding, example below:

    $wp_json_posts->get_post( $post_id, ‘child’ );

    the one caveat is make sure your method that will use this has access to the children post_ids, which it looks like it does based on your pasted code. i will also post this on your post.

    happy coding,
    ~rob

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘A way to utilize the json-rest-api libraries to generate embedded post json’ is closed to new replies.