Get all posts in rest controller


I’m trying to get all posts of a specific type in my custom api controller. I’m not sure, but I think it returns only posts assigned to the currently logged in user. What I’m trying to achieve is returning a list of all posts sfwd-courses and mark each record if a user has an access to it. I guess I have to get a list of all posts then a list of posts connected to specific user and then iterate through them and set a field has_access accordingly. I’m using few plugins: BuddyPress, LearnDash LMS and Memberium for ActiveCampaign.

My controller looks like this:

public function get_courses_v1()
  $args = array('post_type' => 'sfwd-courses', 'nopaging' => true, 'post_status' => 'any',);
  $course_query = new WP_Query();
  $posts = $course_query->query($args);

Unfortunately it returns only posts connected to the currently logged in user only (it returns different records for each user, so I’m assuming that). Do you have any idea what it is like that? Maybe there are some filters or so in the plugins so it filters the records. I used to use WordPress a lot few years ago, but some things have changed, so I’m kinda new in WordPress again and I don’t understand correctly what happens there.

Jakub Saleniuk 2 months 0 Answers 19 views 0

Leave an answer