How to get hp_listing_category image from wp_term

Hi,

I’m stuck getting the image from the hp_listing_category. Here’s my snippet so far.

<?php
$args = [
		'taxonomy' => 'hp_listing_category',
		'hide_empty' => false,
	];
	
	$query = new WP_Term_Query($args);
	$terms = $query->get_terms();
	
	$listings = [];
	
	foreach ($terms as &$term)
	{
		// Remove ones with no parents
		if ($term->parent != 0) {
			
			$listing = new \HivePress\Models\Listing(['id' => $term->term_id]);
			$listings[] = $listing->get_image__url();
		}
	}

The $term->term_id is giving me nothing good. Thank you for any help.

Please try this PHP snippet. Please change 1 on the category id which image you want to take. You will get the image URL as the result

$category = \HivePress\Models\Listing_Category::query()->get_by_id(1);
		
if($category->get_image()){
	$image_url = wp_get_attachment_url($category->get_image_id());
}

Super thank you. That was the method i was looking for !

1 Like

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