Looking to add the parent id to each resulting posts/pages for rest api
-
I’m looking to include a key with each post/page in this resulting query to include the parent id’s but it doesn’t seem t be working I’ve tried doing the things that have been commented out but they weren’t working. I’m looking to try to pass this for a rest api endpoint.
// run query $search_query = new WP_Query(); $search_query->parse_query( $args ); if ( function_exists( 'relevanssi_do_query' ) ) { relevanssi_do_query( $search_query ); } $controller = new WP_REST_Posts_Controller('post'); $posts = array(); // foreach($search_query->posts as $po) { // $po->parent_id = "test"; // } while ( $search_query->have_posts() ) : $search_query->the_post(); // $search_query->post->test = "Test"; $data = $controller->prepare_item_for_response( $search_query->post, $request ); $posts[] = $controller->prepare_response_for_collection( $data ); endwhile; // foreach($posts as $post) { // $post['parent_id'] = wp_get_post_parent_id($post->$id) ; // }
Viewing 9 replies - 1 through 9 (of 9 total)
Viewing 9 replies - 1 through 9 (of 9 total)
- The topic ‘Looking to add the parent id to each resulting posts/pages for rest api’ is closed to new replies.