Skip to content
This repository was archived by the owner on Sep 24, 2018. It is now read-only.
This repository was archived by the owner on Sep 24, 2018. It is now read-only.

How to correctly search using the V2 javascript client #1350

@joneslloyd

Description

@joneslloyd

Hello,

How do I correctly perform a search on a collection of Posts using the JS API in V2?

Currently I have:

var The_Event = wp.api.models.Post.extend({
            urlRoot: WP_API_Settings.root + '/the_event',
            defaults: {
                type: 'the_event'
            }
        });

var The_Events = wp.api.collections.Posts.extend({
            url: WP_API_Settings.root + '/the_events',
            model: The_Event,
        });

var my_events = new The_Events({
        data: {
            filter: {
                s: 'happy',
            },
        },
    });

However, all posts of my CPT are returned, rather than just those with the word 'happy' in (presumably) their title / content.

I've tried replacing this:

var my_events = new The_Events({
        data: {
            filter: {
                s: 'happy',
            },
        },
    });

With this:

var my_events = new The_Events({
        filter: {
             s: 'happy',
         },
    });

Or this:

var my_events = new The_Events({
        s: 'happy',
    });

But nothing seems to return my filtered search results.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions