How do I redirect to a webpage instead of the listing page from the listing block?

How do I redirect to a webpage instead of the listing page from the listing block? When a user clicks on a listing block, I would like for it to redirect to a webpage, instead of opening the detailed listing page.

It’s possible, but this would require code customizations. If you added an URL attribute for listings and you’d like to redirect them to the entered URL, you can try this code snippet:

add_action(
	'template_redirect',
	function(){
		if(is_singular( 'hp_listing' )){
			$listing = HivePress\Models\Listing::query()->get_by_id(get_post());
			
			if(!$listing || !$listing->get_attributenamehere()){
				return;
			}
			
			wp_redirect($listing->get_attributenamehere());
			exit;
		}
	},
	1000
);

It worked! Thank you!

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