Get posts with AnsPress’s category

4.94K viewsWordPress
0

Hello,

My website uses AnsPress to create a Q&A forum and uses AnsPress Category extension to create categories inside the forum. My forum has two categories called “depression” & “anxiety”. These categories are listed by executing the following REST endpoints:

http://ninsutu.com/wp-json/taxonomies/question_category/terms/
<code>[
    {
        "ID": 6,
        "name": "Anxiety Disorder",
        "slug": "anxiety",
        "description": "",
        "taxonomy": "question_category",
        "parent": null,
        "count": 3,
        "link": "http://ninsutu.com/questions/category/anxiety/",
        "meta": {
            "links": {
                "collection": "http://ninsutu.com/wp-json/taxonomies/question_category/terms",
                "self": "http://ninsutu.com/wp-json/taxonomies/question_category/terms/6"
            }
        }
    },
    {
        "ID": 7,
        "name": "Depression",
        "slug": "depression",
        "description": "",
        "taxonomy": "question_category",
        "parent": null,
        "count": 4,
        "link": "http://ninsutu.com/questions/category/depression/",
        "meta": {
            "links": {
                "collection": "http://ninsutu.com/wp-json/taxonomies/question_category/terms",
                "self": "http://ninsutu.com/wp-json/taxonomies/question_category/terms/7"
            }
        }
    }
]</code>

My struggle now is how to retrieve posts listed under “depression” or “anxiety” category.  Following WP-REST API documentation, I can filter posts with standard categories using the following endpoints:

http://ninsutu.com/wp-json/posts?filter[category_name]=myStandardCategory

I’m also able to get all posts with the AnsPress’s question and answer using the following endpoints respectively:

http://ninsutu.com/wp-json/posts?type=question
http://ninsutu.com/wp-json/posts?type=answer

What I’m unable to do is filtering all AnsPress posts with a certain custom AnsPress category. I’ve tried the following but it doesn’t work as category_name filter is probably invalid.

http://ninsutu.com/wp-json/posts?type=question&filter[category_name]=depression
http://ninsutu.com/wp-json/posts?type=question&filter[question_category_name]=depression
http://ninsutu.com/wp-json/posts?type=question&filter[cat]=7

I’m stuck with this for several days, please help.

Thanks

Loc

0

Not tried wp rest with AnsPress. But you can try:

q_cat
question_category
term_id

Try and let us know.