Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!


Help with WP-API. JSON API for WordPress [PHP]
New on LowEndTalk? Please Register and read our Community Rules.

All new Registrations are manually reviewed and approved, so a short delay after registration may occur before your account becomes active.

Help with WP-API. JSON API for WordPress [PHP]

JonchunJonchun Member
edited August 2016 in Help

I've spent about an hour going through the WP-API docs and I can't make heads or tails of this stuff. Instead of spending more time struggling, I figured since it's not urgent I can just wait and see if someone else who already has experience with this can just spoonfeed me in the right direction.

http://v2.wp-api.org/extending/modifying/

I'm trying to use the following snippet I found on Github.

http://pastebin.com/NjSV8Ut3

Where would I even put this? I have no idea how the filters work and the documentation is jsut terrible. Granted, the plugin itself is amazing and provides an out-of-the-box json api for WP that I enjoy using, but trying to extend it has me puzzled. Am I supposed to be making my own plugin? How do I extend this?

If anyone has insight, that would be perfect (I also haven't had sleep for about 25 hours and I'm writing this as I go to sleep... so I might just be missing something really really obvious)

thanks all!

Jonchun

Comments

  • WHTWHT Member

    Test test. 1 2.1 2. Hear me?

  • vpsGODvpsGOD Member, Host Rep

    Thanks for making LET up for beta

  • Test ended? Can I clean up?

  • miaumiau Member
    edited August 2016

    @Amitz said:
    Test ended? Can I clean up?

    Unhanded exception found in End_test.exe.

    Test not ended.

  • This is NOT a test. I repeat: This is NOT a test. The cake is real.

  • https://css-tricks.com/using-the-wp-api-to-fetch-posts/#article-header-id-2

    Scroll down to removing fields and adding fileds

    I have also sent you a pm

  • You can place that code in one of the following places:

    • Create a directory named mu-plugins inside wp-content and place the snippet in a file.
    • Create a file inside wp-content/plugins with this header and place the snippet.
    • Place it in the functions.php file of your current theme/child theme.

    With the first option, the code will always be active, with the second and third options it'll be active if the plugin or theme is active.

    Thanked by 1Jonchun
  • JonchunJonchun Member
    edited August 2016

    @jesin said:
    You can place that code in one of the following places:

    • Create a directory named mu-plugins inside wp-content and place the snippet in a file.
    • Create a file inside wp-content/plugins with this header and place the snippet.
    • Place it in the functions.php file of your current theme/child theme.

    With the first option, the code will always be active, with the second and third options it'll be active if the plugin or theme is active.

    Thanks. This is what I needed. Will give it a shot later.

    Edit: I haven't quite had a chance to try this yet, but I'm really confused at how this would work.

    add_filter( 'json_prepare_post', 'get_pagination_in_json', 10, 3 );
    

    any ideas what the "10" and "3" mean? I see the numbers in like all the examples but I have no idea how that works.

  • RTMF

  • @tommy said:
    RTMF

    what?

  • @Jonchun said:

    @jesin said:
    You can place that code in one of the following places:

    • Create a directory named mu-plugins inside wp-content and place the snippet in a file.
    • Create a file inside wp-content/plugins with this header and place the snippet.
    • Place it in the functions.php file of your current theme/child theme.

    With the first option, the code will always be active, with the second and third options it'll be active if the plugin or theme is active.

    Thanks. This is what I needed. Will give it a shot later.

    Edit: I haven't quite had a chance to try this yet, but I'm really confused at how this would work.

    add_filter( 'json_prepare_post', 'get_pagination_in_json', 10, 3 );

    any ideas what the "10" and "3" mean? I see the numbers in like all the examples but I have no idea how that works.

    10 is the priority of the filter/action(lower executed first higher executed later) and 3 is the number of args required for the function being passsed

    I will send you a pm if i figure it out :-)

  • @Jonchun, message me on skype and I will help you out. Plus my active project is heavily WP-API based. User is pcfreak30.

  • @Jonchun said:

    @tommy said:
    RTMF

    what?

    Read the manual, fucking.
    Makes it much more enjoyable.

  • @daily said:

    @Jonchun said:

    @tommy said:
    RTMF

    what?

    Read the manual, fucking.
    Makes it much more enjoyable.

    I'll remember this next time I go to Ikea.

    Thanked by 1daily
  • @Jonchun Who ever reads manuals? :P

  • Figured it out. For future reference, if anyone wants to add next and previous posts, here's what I did.

    http://pastebin.com/8sknJ0eH

Sign In or Register to comment.