How can I pull listing info from REST API

Hey guys, is there anyway you could help me how can I pull listing info from either hivepress API or Wordpress api, I saw a previous topic about this but that snippet doesn’t seem to work anymore so Hivepress listings don’t appear in the WP Posts rest api.

Thanks a lot

Hi,

Currently, this is only possible through the WP REST API. Listing is a custom post type hp_listing. If necessary, you can enable show_in_rest for the post type.

I am trying to use this snippet, but doesn’t seem to be visible at posts in the rest api, can you help how can I achieve this?

add_filter('register_post_type_args', 'add_rest_api_to_listing_post_type', 10, 2);
function add_rest_api_to_listing_post_type($args, $post_type) {

    if ($post_type !== 'hp_listing') {
        return $args;
    }

    $args['show_in_rest'] = true;
    $args['rest_base'] = 'hp_listing'; // Optional: Custom endpoint base
    $args['rest_controller_class'] = 'WP_REST_Posts_Controller'; // Controller class

    return $args;
}

Please try this PHP code snippet to manage the hp_listing post type parameters. For example, it is possible to add a show_in_rest parameter to this post type in this way. Also, this article could be helpful for you Adding REST API Support For Custom Content Types | REST API Handbook | WordPress Developer Resources. But please note that it can require further advanced customization. If you are not familiar with the code customization, then please consider hiring someone for custom work https://fvrr.co/32e7LvY

add_filter(
	'hivepress/v1/post_types',
	function( $post_types ) {
		$post_types['listing']['show_in_rest'] = true;

		return $post_types;
	},
        1000
);

Thank you so much this works well, one more question, is there any chance to get other listing informations such as vendor, price and other attributes?

Are you planning to extend your Rest API in the near future, to have better access for all of this?

Hi,

If the listing is an object, you can get this information, please check this doc Models - Developer Docs

Yes, we are planning to improve the Rest API.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.