Pulling listing info with Wordpress REST API

Is there a way of getting a json with all the parameters from a listing?

How can I make the listing custom post type available in Wordpress rest API?

Just solved it by adding:

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 ) {
	// Let's make sure that we're customizing the post type we really need
	if ( $post_type !== 'hp_listing' ) {
		return $args;
	}
	
	$args['show_in_rest'] = true;
	
	return $args;
}

to functions.php

Thanks for sharing! Please note that this code snippet will also probably enable the block editor for listings in WordPress/Listings.
We plan to add a HivePress-specific REST API endpoint for fetching listings in future versions.

Thank you for editing my code block into a readable format!

One extra question: Now that it’s working, it only outputs basic stuff like listing title, slug, URL, etc. but custom attributes such as “Price” or “Condition” that I’ve created are not showing.

Is there a way of adding them that you can think of?

I’d also really like to know if the listing is featured or not.

Yes, since it’s a default WordPress endpoint it returns only the basic post fields, but you can try also fetching the meta fields prefixed with “hp_”, for example the featured status is stored in “hp_featured” meta field.

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