How to show % of profile completeness in WP Dashboard>Listings (backend) and frontend listings?

Hi, I want to show profile completeness both in backend and frontend. This will help to easily find the incomplete listings and contact them. Additionally, if a company see that their profile is incomplete, they will tend to fill all the details.

More details:

I have 12 custom listing attributes:

  • status
  • managing_authority
  • industries
  • minimum_investment
  • foreign_ownership
  • tax_incentives
  • corporate_tax
  • customs_benefits
  • connectivity
  • available_facilities
  • business_setup
  • phone

I want to add a custom column to WP Admin → Listings showing profile completeness, for example:

75% (9/12)

The value should be calculated dynamically based on whether each attribute has a value.

Industries is a multi-select attribute and should count as complete when at least one option is selected.

I tried checking hp_ post meta and hp_listing_ taxonomies, but the attributes are not being detected correctly. I also tried accessing the listing object with get_status(), get_phone(), etc., but that did not work either.

What is the recommended HivePress API/function for retrieving the value of a custom listing attribute by its field name from a listing ID?

Ideally, I’d like a code example showing how to retrieve the value of an attribute such as status or phone.

Thanks.

Hi,

Unfortunately there’s no such UI feature yet, but thanks – we’ll consider adding it. Please try the sample code snippet below, if you set a list of field names that should be included in the progress calculation, the progress should appear both on the front-end Account/Listings page, and in the dashboard Listings table:

// Get listing completeness, e.g. "75% (9/12)".
function hp_get_listing_completeness( $listing ) {
	$names = [ 'business_status', 'managing_authority', 'industries', 'minimum_investment', 'foreign_ownership', 'tax_incentives', 'corporate_tax', 'customs_benefits', 'connectivity', 'available_facilities', 'business_setup', 'phone' ];

	$fields = $listing->_get_fields();
	$filled = 0;

	foreach ( $names as $name ) {
		if ( isset( $fields[ $name ] ) && ! in_array( $fields[ $name ]->get_value(), [ null, '', [] ], true ) ) {
			$filled++;
		}
	}

	return sprintf( '%d%% (%d/%d)', round( $filled / count( $names ) * 100 ), $filled, count( $names ) );
}

// Add column to WP Admin > Listings.
add_filter(
	'manage_hp_listing_posts_columns',
	function( $columns ) {
		return array_merge( $columns, [ 'completeness' => 'Completeness' ] );
	}
);

add_action(
	'manage_hp_listing_posts_custom_column',
	function( $column, $post_id ) {
		if ( 'completeness' === $column ) {
			$listing = \HivePress\Models\Listing::query()->get_by_id( $post_id );

			if ( $listing ) {
				echo esc_html( hp_get_listing_completeness( $listing ) );
			}
		}
	},
	10,
	2
);

// Add column to Account > Listings on the front-end.
add_filter(
	'hivepress/v1/templates/listing_edit_block',
	function( $template ) {
		return hivepress()->template->merge_blocks(
			$template,
			[
				'listing_container' => [
					'blocks' => [
						'listing_completeness' => [
							'type'     => 'callback',
							'callback' => 'hp_render_listing_completeness',
							'return'   => true,
							'_order'   => 45,
						],
					],
				],
			]
		);
	}
);

add_filter(
	'hivepress/v1/blocks/callback',
	function( $args ) {
		if ( isset( $args['callback'] ) && 'hp_render_listing_completeness' === $args['callback'] ) {
			$args['params'] = [ $args['context']['listing'] ?? null ];
		}

		return $args;
	}
);

function hp_render_listing_completeness( $listing ) {
	return $listing ? '<td class="hp-listing__completeness">' . esc_html( hp_get_listing_completeness( $listing ) ) . '</td>' : '';
}

Hope this helps