Change the order of a specific attribute on listing view block

Hi,

I am trying to change the order of a specific attribute on the listing view block. I have used the below code that moves all attributes to the left.

add_filter(
	'hivepress/v1/templates/listing_view_block',
	function( $template ) {
		return hivepress()->helper->merge_trees(
			$template,
			[
				'blocks' => [
					'listing_header' => [
						'blocks' => [
							'listing_actions_primary' => [
								'type'  => 'container',									 
										'_order'     => 1,
										'attributes' => [
											'class' => [ 'hp-listing__actions', 'hp-listing__actions--primary' ],
										],
							],
						],
					],
				],
			]
		);
	},
	1000
);

  

But what I need is to move a specific attribute to the left and the rest of the ordering be as it is(listing title, content, description, listing actions etc)

Can anyone please help how to achieve this?

Thanks.

Thank you for waiting.

If you want to change the position of the custom attribute in the HivePress/Attributes, please change Order in the attribute settings.

If you want to change the position of the custom attribute, which is not in the HivePress/Attributes, please try to change the Order of the attribute with this code snippet.

add_action(
	'template_redirect',
	function(){
		wp_update_post([
			'ID' => put attribute ID here,
			'menu_order' => put new attribute order here,
		]);
	},
	1000
);

But please note that it can require changing the order the same way for other attributes to move another attribute to another place.

Thanks for the reply, but this changes the attribute ordering within the “attributes” section where all attributes are displayed. To explain it better I have added a screenshot below.

As seen in the above image, I want to move the custom Hivepress attribute to the left side, before the title starts. The end result would be something like the below image

Sorry, there’s no simple code snippet for this. It would require a custom implementation.

It is needed to hide this attribute with CSS which you want to move, and then it is possible to get and show the value of the listing attribute in your custom place in the listing block with the hook hivepress/v1/templates/listing_view_block/blocks

If you are not familiar with the code customization, then please consider hiring someone for custom work https://fvrr.co/32e7LvY

Thanks for the pointers, after some tweaking I am now able to display the custom attribute by using the below line of code

echo $listing->get_price();

The above line returns the value of the hivepress custom attribute named “price”.

However, if I use the same logic to display another hivepress custom attribute that is a select field, it doesn’t show anything. For eg: I am trying the below line of code

echo $listing->get_listing_type();

In the above context “listing_type” is the custom attribute, why then it doesn’t show anything? Is there anything else I have to do to display the value of a select field vs a text field?

Please try this code snippet for selectable attributes. Please change display_put_attrbute_field_name on display_ + field name of the attribute

$listing->display_put_attrbute_field_name()

Thanks a lot! This worked. Is there a documentation anywhere where I could have found out about this? I tried searching everywhere on the Hivepress documentation website and Github code snippets but coundn’t find any references on how to achieve this.

Yes, there is our Developer Docs, where you can find a lot of helpful information for developing

Also, it is possible to find solutions in Code Snippets Library or on our community forum

These sources always updated with new information

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