WordPress.org

Ready to get started?Download WordPress

Forums

JSON API
field selector (6 posts)

  1. aleclofabbro
    Member
    Posted 6 months ago #

    Hello,
    is it possible to retrieve just a set of fields in response?
    e.g:
    http://example.com/?json=get_posts&fields=id,title

    {
    status: "ok",
    count: 2,
    count_total: 2,
    pages: 1,
    posts: [
    {
    id: 14,
    title: "post3"
    },
    {
    id: 8,
    title: "posr2"
    }
    ],
    query: {
    ignore_sticky_posts: true
    }
    }

    http://wordpress.org/plugins/json-api/

  2. Bob Gregor
    Member
    Posted 5 months ago #

    Yes! Change fields to "include" in your example:

    http://example.com/?json=get_posts&include=title

    Just an FYI - ID is always returned

    For more detail see http://wordpress.org/plugins/json-api/other_notes/#3.3.-Using-include/exclude-and-redirects

    To see which fields you can include/exclude, look @ the relevant model / response objects: http://wordpress.org/plugins/json-api/other_notes/#4.-Response-objects

  3. aleclofabbro
    Member
    Posted 5 months ago #

    Thank you!
    sorry i should have read it myself!
    another thing:
    what about the feature of a conditional query on custom_fields ..
    like "custom_fields.size > 10"
    if there's not this feature could you help me pointing me out where to focus for this extension ?
    Thank you very much!

  4. Bob Gregor
    Member
    Posted 5 months ago #

    See http://wordpress.org/plugins/json-api/other_notes/#3.2.-Content-modifying-arguments

    You'll be looking for the last line in that section: meta_key, meta_value & meta_compare. The keys are not defined there, however, so...

    JSON API uses the same parameters as WP_Query, if the JSON API docs are fuzzy or do not provide a context - the codex will help. I found the reference for your example here: http://codex.wordpress.org/Class_Reference/WP_Query#Custom_Field_Parameters

    So, in your case, you're going to specify meta_key = "size", meta_value = 10, meta_compare = '>'

    meta_compare (string) - Operator to test the 'meta_value'. Possible values are '!=', '>', '>=', '<', or '<='. Default value is '='.

  5. aleclofabbro
    Member
    Posted 5 months ago #

    I'm testing it now.
    yes, i'm making it work!
    but is it also possible to format the url query to handle multiple queries as specified in http://codex.wordpress.org/Class_Reference/WP_Query#Custom_Field_Parameters as new WP_Query( array (.<arrays_of_queries>.)) ?

  6. Bob Gregor
    Member
    Posted 4 months ago #

    Off the top of my head - I'm going to say no - I think multiple custom field queries are beyond the scope of the plugin. I'd ask Dan to chime in here for more info - he's the expert. If it doesn't support it, I'd suggest extending it if you want to perform complex queries like that.

Reply

You must log in to post.

About this Plugin

About this Topic