User_view_block not rendering

Hi,

When using this small piece of code, the block only renders for vendors, but never does for users.

The ‘user_view_block’ does not render despite being a valid User Object.
if I try printing “$follower_user->get_id()” or any other user attribute, it correctly prints the user attribute,
I also use a similar piece of code somewhere else on the page and it displays flawlessly there.

Do you have any idea of what the issue could be?
Thank you

Screenshot from 2023-09-15 15-14-37

Hi, copy & paste the code you used as a reply & ill see if I can figure out the problem.

Hi, here’s the code. “$followers_ids” contains an array of user_ids. (I modified the foo-follower extension to work with user_ids)
I then check if the ID is linked to either a vendor or a user object and output the corresponding block.

It doesn’t show any error and simply prints nothing when trying to output a user_view_block. If I try simply printing $follower_user->get_id() it works, which means there’s a user object.

$output = '';
foreach( $followers_ids as $follower_id ){
	if( $follower_id && $follower_id !== ''){
		$follower_user = HivePress\Models\User::query()->get_by_id( $follower_id );
		$follower_vendor = HivePress\Models\Vendor::query()->filter(['user' => $follower_id])->get_first();
		if( $follower_vendor && $follower_vendor->get_status() === 'publish' ){
			$output .= ( new HivePress\Blocks\Template(
				[
					'template' => 'vendor_view_block',

					'context'  => [
						'vendor' => $follower_vendor,
					],
				]
			) )->render();
		} elseif( $follower_user ) {
			$output .= ( new HivePress\Blocks\Template(
				[
					'template' => 'user_view_block',

					'context'  => [
						'user' => $follower_user,
					],
				]
			) )->render();
		}
	}
}
return $output;

Thank you for your help!

We have not reproduced this issue. It works correctly. Please send more details that may help to detect or reproduce this issue (e.g., where you try to put this code snippet, please send the full code snippet with a hook if you use such one).

I found the solution, I had conflicts with using the ‘user’ context with another snippet. Thank you for your help.

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